用來做全局腳本的、先實體化一個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的作用是什么?全局脚本和普通脚本有什么区别?通常用于什么情况?

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 kk匡 的頭像
    kk匡

    kk匡的日記&學習筆記

    kk匡 發表在 痞客邦 留言(0) 人氣()