Skip to content

Instantly share code, notes, and snippets.

@cjacobwade
Created March 29, 2015 03:14
Show Gist options
  • Save cjacobwade/d2db04ff32a729570c72 to your computer and use it in GitHub Desktop.
Save cjacobwade/d2db04ff32a729570c72 to your computer and use it in GitHub Desktop.
Saving references
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