怎么使用呢?如下面一個MonoBehaviour 成為場景中對象的行為后,他就會一直訪問這個myString的變量了。 using UnityEngine; using System.Collections;
public class Action1 : MonoBehaviour {
// Use this for initialization void Start () { } // Update is called once per frame void Update () { if(ModelLocator.getInstance.myString!=null && ModelLocator.getInstance.myString!=""){ //do somethings; } } }
下面是另一個MonoBehaviour 做的事: using UnityEngine; using System.Collections;
public class Action2 : MonoBehaviour { public bool state=true; // Use this for initialization void Start () { } // Update is called once per frame void Update () { if(state){ ModelLocator.getInstance.myString="I'm a Unityer!"; }else{ ModelLocator.getInstance.myString=""; } } }