Persistence Across Levels
MonoBehaviours are re-instantiated when each level is loaded, so to retain a value between levels, you can use a static variable.
- Update (until object is destroyed)
Q move view W translate E rotate r scale
To be able to use prefabs effectively, references needed by behaviours should be found by the behaviours themselves, instead of relying on user input in the inspector, as references external to the gameobject are not stored in the prefab.
Finding other gameobjects can be done in different ways:
- Finding by type - if there only is a single gameobject of a certain type, or all objects of a certain type is needed, this is the easiest and safest way to do this.
- Getting references from singleton classes, e.g. MainCharacter.Instance .
- Getting references from singleton lookup classes, e.g. EnemyFactory.Instance.GetEnemyType(Enemy.Type.Thing)
- Finding by name - the name can be stored in the prefab and accessed in the inspector.