首页 > 其他 > 详细

u3d静态函数

时间:2014-10-15 12:19:11      阅读:128      评论:0      收藏:0      [点我收藏+]
using UnityEngine;
using System.Collections;

public class Manager : MonoBehaviour
{
    private static  Manager m_Instance;

    public static Manager instance
    {
        get
        {
            return m_Instance;
        }
    }
    // Use this for initialization
    void Start ()
    {
        m_Instance = this;
    }

    public void Gprint()
    {
        Debug.Log("Gprint");
    }

    public static void print()
    {

        Debug.Log("this is Manager");
    }

    // Update is called once per frame
    void Update ()
    {

        

    }
}

下面脚本调用

using UnityEngine;
using System.Collections;

public class test : MonoBehaviour 
{

    private Manager maager;
    void Start () 
    {
        
    }
    
    // Update is called once per frame
    void Update ()
    {
        maager = Manager.instance;
        maager.Gprint();
        Manager.print();
    
    }

   

    void OnGUI()
    {
       // GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), tex);
       
    }
}
 maager = Manager.instance; 放到update里面,是因为每个脚本的Start执行时间不一样,不能确保manager的start就一定在Test类的前面执行,所以放到update里面更保险
类的成员函数就使用得到的,静态的方法使用类的头

u3d静态函数

原文:http://www.cnblogs.com/dragon2012/p/4025931.html

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