How do you activate a script upon play?

I am really new to unity, and have really know experience besides Unity Tutorials :stuck_out_tongue: I was wondering what key phrase would mean to start the script upon the start of a game?

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
}

}

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);

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