Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

enter image description hereI'm making a 2D sidescrolling game in Unity, and when the player shoots an obstacle, I want the obstacle animation to play and then destroy itself. I got it to destroy itself, but the animation won't play. Any suggestions?

public class obstacleAnim : MonoBehaviour {

protected Animation obsanim;

// Use this for initialization
void Start () {

    obsanim = GetComponent<Animation> ();

}

// Update is called once per frame
void Update () {

}

void OnCollisionEnter2D(Collision2D col)
{
    if (col.gameObject.tag == "circle") 
    {
        obsanim.Play ("circobs");
        Destroy (gameObject, 1.0f);
    }
}

}

thank you for any help!

share|improve this question

1 Answer 1

I tested your script and it works as expected. The problem is most likely the animation itself. You should enable autoplay from the Animation component and see if your animation works without the script. Also make sure there are no errors in the console. Click the error counter in case you have accidentally hidden them.

share|improve this answer
    
The animation worked fine before I implemented the script, but now it won't play I don't know why –  Jordan Dec 27 '14 at 20:17
    
I added a picture –  Jordan Dec 27 '14 at 20:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.