First of all, don't use DontDestroyOnLoad in your update function. Use it in your Start or Awake funciton.
Secondly you can access your Non-Destroyed object like you would any other object.
Only differences between the two is that the Non-Destroyed stays in the scene when changing scenes.
Here are some ways to access it:
var obj = GameObject.Find("My Non Destroyed Object Name");
Or my personal favorite, if the object is used for scoring or settings I'll create a new gameobject and add the following script to it:
public class GameManager : MonoDevelop {
/* These are all script on the same gameobject that is not being destroyed */
public static Settings settings;
public static PlayerMananger playerMananger;
public static UIManager uiManager;
void Start() {
DontDestroyOnLoad(this.gameobject);
// Get the components
settings = GetComponent<Settings>();
playerMananger = GetComponent<PlayerMananger>();
uiManager = GetComponent<UIManager>();
}
}
Now I can create a script from anywhere and I can access all these Manager and setting files simply using:
var settings = GameManager.settings;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…