What is a GameObject?
Name any 3 elements of the Unity Editor
Make complex GameObject hierarchies reusable
Further details here
A set of functions executed over a scripts lifetime in a predetermined order by the engine
Further details for its Unity implementation here
Base class for all Unity scripts. Determines what parts of the event loop the script will be in.
Most important messages*/properties are:
Allows for much faster and easier parameter tweaking
Can be done by:
Values in the editor take precedence over values in the script
Let's modify the transform component
//Dragging and dropping from the editor
GetComponent<ComponentType>();
GetComponentInChildren<ComponentType>();
GetComponentInParent<ComponentType>();
FindObjectOfType<SomeType>();
//Again dragging and dropping from the editor
GameObject.Find("SomeName");
GameObject.FindObjectWithTag("SomeTag");
transform.parent;
transform.GetChild(int clildIndex);
GameObject myGameObject = Instantiate(Object original,
Vector3 position,
Quaternion rotation);
//...
var component1 = myGameObject.GetComponent<ComponentType>();
//...
var component2 = myGameObject.AddComponent<ComponentType>();
//...
Destroy(myGameObject);
// true if the key is pressed
Input.GetKey(KeyCode.SomeKey);
// true the first frame the key is pressed
Input.GetKeyDown(KeyCode.SomeKey);
// true the first frame the key is released
Input.GetKeyUp(KeyCode.SomeKey);
Configurable in Edit/Project Settings/Input Manager
// "ButtonName" = "Fire1" for left mouse button
Input.GetButtonXXX("ButtonName");
// Smoothed input
Input.GetAxis("AxisName");
// Raw input
Input.GetAxisRaw("AxisName");
// "AxisName" = "Horizontal" for A/D
// "AxisName" = "Vertical" for W/S
Configurable in Edit/Project Settings/Input Manager
Vector3 moveDirection =
new Vector3(Input.GetAxis("Horizontal"),
0,
Input.GetAxis("Vertical"))
.normalized
* Time.deltaTime
* moveSpeed;
Vector3 pointToLookAt = transform.position
+ moveDirection * 100;
transform.position += moveDirection;
transform.LookAt(pointToLookAt);