怎么使用呢?如下面一個(gè)MonoBehaviour 成為場(chǎng)景中對(duì)象的行為后,他就會(huì)一直訪問(wèn)這個(gè)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; } } }
下面是另一個(gè)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=""; } } }