Unity Shit

Links

Official

Unofficial

Shaders

Cheat Sheet

Get a component

Rigidbody rb = GetComponent<Rigidbody>();

Getting child GameObjects

// All GameObjects have a transform, so we can use that to get all children.
Transform[] waypoints;
waypoints = new Transform[transform.childCount];
int i = 0;
foreach (Transform t in transform) {
    waypoints[i++] = t;
}

Find GameObjects by Name/Tag

GameObject player = GameObject.Find("MainHeroCharacter");
GameObject player = GameObject.FindWithTag("Player");
GameObject[] enemies = GameObject.FindGameObjectsWithTag("Enemy");

Event Functions

void Update(){}         // Called before a frame is rendered
void FixedUpdate(){}    // Called before a physics update

void LateUpdate(){}     // Called after Update, FixedUpdate, and
                        // animation calculations finish for all objects

void Awake(){}          // Called when scene loads
void Start(){}          // Called after all Awake calls have finished

// For normal physics collisions:
OnCollisionEnter(){}
OnCollisionStay(){}
OnCollisionExit(){}

// For colliders:
OnTriggerEnter(){}
OnTriggerStay(){}
OnTriggerExit(){}

Full execution order is here.

Setting Time-Scale

This doesn’t slow down updates, but changes the reported deltas to make time seem slower/faster.

Time.timeScale = 0.5; // 50% speed

Creating and Destroying GameObjects

GameObject enemy;
Instantiate(enemy);
Destroy(enemy);

Destroy(this); // WRONG. Destroys the script component running it, not the GameObject.