Play an animation?

How do i play an animation OnTriggerEnter()

i tryed this:

function OnTriggerEnter(collision : Collider)
{
	
	if(collision.transform.name == "Ball")
	{
		Debug.Log("cyl hit! :smile:");
		audio.Play();
		
		//Animation play...
		animation.Play("CylAnim2");	
	
	}
}

also tryed to remove the “CylAnim2” and there is only one animation on this object
the audio is playing but the animation is not :face_with_spiral_eyes:

Try using

anim.Play('Walk");

Though I’ve been using the following to check its not already playing (I had an issue where it kept restarting on the first frame and thus looked static).

if (!anim.IsPlaying("Walk")) anim.Play('Walk")'

Hope that works for you

Thanks for the reply

if i just do anim.Play(“CylAnim2”); it gives me an error:
Assets/Scripts/bonusCyl.js(12,17): BCE0005: Unknown identifier: ‘anim’.
any idea ;o?

Oh, you’ll have to define what anim represents first.
As currently anim is pointing to nothing as its not previously referenced in the script.

I’m still very basic in scripting knowledge so unfortunately I don’t think I’ll be able to help much more than this.

ahh okay, I’m new to scripting ;o, trying to fix this but no luck :stuck_out_tongue: