Creating Scripts Flashcards
transform on GameObject
accessible in script with just .transform, inherits from “transform” visible in Unity inspector.
Time.deltaTime
time to render previous frame
Update() method called how often?
every frame
Time.time
true time since start of game
tranform.Translate(…)
translates object
namespaces
establish groupings between related objects
UnityEngine
namespace referring to when app is running
UnityEditor
namespace referring to extending Unity editor
jump directly in docs from Unity UI how?
click on book+? symbol in inspector
create script how?
from unity editor
: Monobehavior
MonoBehaviour is the base class from which every Unity script derives.
Start()
Start is called on the frame when a script is enabled just before any of the Update methods are called the first time.
Like the Awake function, Start is called exactly once in the lifetime of the script. However, Awake is called when the script object is initialised, regardless of whether or not the script is enabled. Start may not be called on the same frame as Awake if the script is not enabled at initialisation time.
The Awake function is called on all objects in the Scene before any object’s Start function is called. This fact is useful in cases where object A’s initialisation code needs to rely on object B’s already being initialised; B’s initialisation should be done in Awake, while A’s should be done in Start.
Where objects are instantiated during gameplay, their Awake function is called after the Start functions of Scene objects have already completed.
Update()
Update is called every frame, if the MonoBehaviour is enabled.
Update is the most commonly used function to implement any kind of game script. Not every MonoBehaviour script needs Update.
interact with GameObjects in script
- create empty GameObject in Unity.
- create script
- drag script onto GameObject
Quaternion.identity
how to rotate object; identity same as matrix identity, not rotation