MonoBehaviour.Awake() in Unity 5.5
from: https://docs.unity3d.com/ScriptReference/MonoBehaviour.Awake.html
Awake is called when the script instance is being loaded.
- Awake is used to initialize any variables or game state before the game starts.
- Awake is called only once during the lifetime of the script instance.
- Awake is called after all objects are initialized so you can safely speak to other objects or query them using eg. GameObject.FindWithTag .
- Each GameObject ‘s Awake is called in a random order between objects.
- Awake is always called before any Start functions.
- Use Awake instead of the constructor for initialization, as the serialized state of the component is undefined at construction time.
- Awake cannot be a co-routine.
using UnityEngine; using System.Collections; public class ExampleClass : MonoBehaviour { private GameObject target; void Awake() { target= GameObject.FindWithTag("Player"); } }