UNITY TUTORIAL | SCRIPTING | Awake() and Start()

UNITY TUTORIAL | SCRIPTING | Awake() and Start()

Awake()

  • Awake() is called first even if the script component is not enabled
  • Awake() is best used for setting up any references between scripts and initialization

Start()

  • Start() is called after Awake() immediately before the first Update()
  • Start() is called only if the script component is enabled
  • Start() is used for anything we need to occur
  • Start() is only called once in the life time of a script on a gameObject
  • It is impossible to repeat Start()
  • all of the codes in Start() are called on the first frame that the script is active

Example)

  • Awake()
    • set ammo for “enemy” gameObject
  • Start()
    • allow “enemy” to shot
3
Awake() | Start()
4
Awake() called
5
Awake(), Start() called

UNITY TUTORIAL | SCRIPTING | Scopes and Access Modifiers

 

2
Local Variable

 

Scopes and Access Modifier
Local Variable
4
Access Modifier | Public | Private
5
Scripts Attached
6
Pubic Variable in the Inspector
7
Public Variable modified in the Inspector
8
Using a Class Public in another
9
Declaring an Object from another Public Class
10
Declaring an Object from another Public Class in a method
11
Declaring an Object from another Public Class in a method
13
using the variable from another​ Class | only Public variables are visible

 

141.png
using the variable from another​ Class | only Public Methods are visible

15