unity play animation code example
Example 1: play sound unity
AudioSource audioData;
void Start()
{
audioData = GetComponent<AudioSource>();
audioData.Play(0);
Debug.Log("started");
}
Example 2: 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 3: play animation through script unity
animator.Play("StateName");