码迷,mamicode.com
首页 > 其他好文 > 详细

单列范例

时间:2014-05-21 11:51:43      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:style   blog   class   c   code   java   

bubuko.com,布布扣
using UnityEngine;
using System.Collections;

public class wht : MonoBehaviour {

    static wht myInstance;
    public int x = 0;
    static int instances = 0;
    // Use this for initialization

    //Returns the instance
    public static wht Instance
    {
        get
        {
            if (myInstance == null)
                myInstance = FindObjectOfType(typeof(wht)) as wht;
            
            return myInstance;
        }
    }

    void Start () {
        instances++;
        
        if (instances > 1)
            Debug.Log("Warning: There are more than one Level Generator at the level");
        else
            myInstance = this;
    }
    
    // Update is called once per frame
    void Update () {
    
    }
}
bubuko.com,布布扣
bubuko.com,布布扣
using UnityEngine;
using System.Collections;

public class wht1 : MonoBehaviour {

    // Use this for initialization
    void Start () {
        wht.Instance.x = 20;
        Debug.Log(wht.Instance.x.ToString());
    }
    
    // Update is called once per frame
    void Update () {
    
    }
}
bubuko.com,布布扣

 

单列范例,布布扣,bubuko.com

单列范例

标签:style   blog   class   c   code   java   

原文地址:http://www.cnblogs.com/softimagewht/p/3740476.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!