Created
March 29, 2015 03:14
-
-
Save cjacobwade/d2db04ff32a729570c72 to your computer and use it in GitHub Desktop.
Saving references
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Animator anim = null; | |
void Start() | |
{ | |
// this saves a reference to the Animator | |
// way better because you don't have to do an expensive getcomponent each time | |
anim = GetComponent<Animator>(); | |
} | |
void Update() | |
{ | |
if(Input.GetKeyDown(KeyCode.O)) | |
{ | |
anim.Play("DoorOpen"); | |
} | |
// ...etc | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment