Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Simple Sprite Explosion Animation Questions

Discussion in '2D' started by imgodot, Dec 30, 2013.

  1. imgodot


    Nov 29, 2013

    I just started playing around with animating a sprite using a sprite sheet.
    I have been searching the forums and following links (broken and otherwise) for a couple of hours and I'm frustrated.

    My goal is to have a prefab explosion animation that I can instantiate when needed and have it play through once and stop.

    I can drag a selected set of sprite sheet images into the hierarchy and it asks me to assign a name to a new "*.anim" file.
    Then a new object is created in the hierarchy (which appears to be a sprite) and an "Animator" component is added to it.
    If I run the scene the animation starts playing and repeats in a loop.
    All well and good.

    I name the sprite "Explosion" and move if from the hierarchy into my Resources folder.
    Then I instantiate it from a "Start()" event like this:
    Code (csharp):
    1. exp = (GameObject)GameObject.Instantiate(Resources.Load ("Explosion"));
    When I run the scene the explosion is created and begins animating in a loop.

    If I try and access any animation related properties via my "exp" variable (such as: exp.animation.Stop();) it tells me I need to add an "Animation" component.

    1) My animation runs without an "Animation" component, do I really need it for scripting or are there ways around it.

    2) If I need an an "Animation" component then I drag my sprite sheet into the "Animation" slot on the "Animation" component, correct?

    If I do (1 and 2) and try "exp.animation.Stop();" on a mouse click, I get no errors, but the animation keeps on animating.
    3) How do I prevent my animation from animating until I tell it to?

    4) What is the best way to destroy the animation when it has finished animating?

    Thanks for reviewing this long-winded topic.
    Any help is appreciated.

    -- Paul