GetComponent().Play Code Example


Example 1: how to play animation with code in unity


public GameObject ExampleNPC;

void Update()
{
if(Input.GetButtonDown("Animation")) // Make sure to refrence this in Input settings
{
ExampleNPC.GetComponent<Animator>().Play("Anim name");
}
}

Example 2: play animation through script unity


animator.Play("StateName");

Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable