用來做全局腳本的、先實體化一個class、就可以global access到腳本里。
// Unity.Instance
using UnityEngine;
using System.Collections;
public class GameManager : MonoBehvviour {
public static GameManager Instance = null;
GUIText txt_life;
void Start() {
Instance = this;
txt_life = this.transform.FindChild("txt_life").GetComponent<GUIText>();
}
public void Setlife(int life) {
txt_life.text = life.ToString();
}
}
m_life = 0;
GameManager.Instance.SetLife(m_life) ;
c#中的 Instance的作用是什么?全局脚本和普通脚本有什么区别?通常用于什么情况?
全站熱搜