- Home /
Question by
casteponters · Mar 12, 2015 at 03:15 PM ·
c#animationanimatorplay
On Hit play animation
Hi all,
i have my animation called destroy, and i attached on my box object. This animation change sprite and no work! When i call my animation from script report :
"The animation state destroy could not be played because it couldn't be found! Please attach an animation clip with the name 'destroy' or call this function only for existing animations."
This is my code:
if (Input.GetMouseButtonDown(0))
{
RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
if (hit.collider != null)
{
//Se ha colpito il box distruggo il box
if (hit.collider.gameObject.tag == "Box")
{
hit.collider.gameObject.animation.Play("destroy");
//Destroy(GameObject.Find(hit.collider.gameObject.name));
//BoxCount -= 1;
}
}
}
I tryed to replace in debug mode animation Type to 1, but doesn't work.
Help me please.
cattura.jpg
(11.7 kB)
Comment
$$anonymous$$ake sure your Box on the scene has animation component.
Box has "Box" Tag marked
Try to play animation automatically at start and check if everything with your "destroy" anim is ok.
I can't find any bugs in your code. Probably you do something wrong in your Editor.