- Home /
How do you activate a script upon play?
I am really new to unity, and have really know experience besides Unity Tutorials :P I was wondering what key phrase would mean to start the script upon the start of a game?
Answer by Nanobrain · Jan 21, 2014 at 11:45 PM
For a script to be 'activated' it must be attached to a gameobject. Then when the game is ran, the 'Start' method in your script will be called immediately. In this method you can place any code which should be initialised for that object.
public class myGameObjectScript: MonoBehavior {
public void Start() {
// place code here
}
}
Answer by getyour411 · Jan 21, 2014 at 11:13 PM
Add the script to a GameObject in Hierarchy.
Awake, Start, Update, LateUpdate, etc are all active when you press play. If you are specifically asking how to turn off/turn on objects and their scripts, look at SetActive(bool);
Answer by Exalia · Jan 21, 2014 at 11:33 PM
void Start() is called when the scene starts
void Update() is called every frame
void FixedUpdate() is called every 0.2seconds (you can change this value)
void Awake() plays every time the script becomes active
I hope this helps