首页 > 其他 > 详细

单列范例

时间:2014-05-21 11:52:20      阅读:366      评论:0      收藏:0      [点我收藏+]
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

单列范例

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!