How to use Start and Awake functions in Unity

You can follow the original article here.

When a script is loaded in Unity, the functions Awake and Start are called automatically.

using UnityEngine;
using System.Collections;
public class UseFunctions : MonoBehaviour
{
void Awake ()
{
//Write your script
}
void Start ()
{
//Write your script
}
}

The Awake function is always called first even if the script component is not enabled. After the first update Start will be called, only with the script component enabled.

This means that if you have to delay some process in your game, until the script component is not enabled Start will not procede with the initialization.

An example, could be spawning an opponent in the game, having set his life points and ammos with Awake, you could make him move or shoot with Start.

Note that those two functions can only be read once in the execution lifetime. So disabling and enabling the component will not run the code multiple times.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
How To Tech

How To Tech

Quick tutorials on Photoshop, Unity 3D, Facebook, WhatsApp, Windows and some Game news