怎么使用呢?如下面一个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=""; } } }