In continuation of my question about collision caching. I have a script on the manager object with:
private static MyManagerScript instance; public static MyManagerScript Instance { get { if (instance == null) { instance = GameObject.FindObjectOfType<MyManagerScript> (); } return MyManagerScript.instance; } } What is the best way to contact this manager in an object? Option 1:
// напрямую? MyManagerScript.Instance.SomeInt; Or option 2:
private int myInt; // Use this for initialization void Start () { myInt = PauseManagerScript.instance.SomeInt; } // и уже работать с myInt вместо PauseManagerScript.instance.SomeInt // А затем, если нужно, делать PauseManagerScript.instance.SomeInt = myInt
private staticfor the field may not be enough, try adding avolatilesign if you need all threads to see your instance. - nick_n_apublic int SomeInt { get { return paused; } }public int SomeInt { get { return paused; } }, ie no object can change values in the manager, but only receives them? That is,А затем, если нужно, делать PauseManagerScript.instance.SomeInt = myIntis canceled - Krem Sodavolatile. It is intended for C ++ programmers, but the explanations should be clear. - Lunar Whisper