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里面更保险
类的成员函数就使用得到的,静态的方法使用类的头

相关文章:

  • 2022-03-09
  • 2022-12-23
  • 2022-12-23
  • 2021-12-23
  • 2021-06-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-17
  • 2021-12-18
  • 2021-04-01
  • 2021-07-30
  • 2022-12-23
  • 2021-06-19
相关资源
相似解决方案