• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by pintee · Aug 21, 2012 at 06:33 AM · spritemanager2

Play animation then destroy

Hi guys, I have a cat splatting on the ground and i want it so that the splat animation plays and then the object is destroyed. How do you make sure an animation plays to the end before you perform an action? At the moment the object is destroyed before the animation gets played. I'm using spritemanager2 btw. Thanks.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AlucardJay · Aug 21, 2012 at 07:17 AM 0
Share

you can check if an animation is playing with

 animation.isPlaying

http://docs.unity3d.com/Documentation/ScriptReference/Animation-isPlaying.html

http://docs.unity3d.com/Documentation/ScriptReference/Animation.html

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Panik.Studios · Aug 21, 2012 at 08:29 AM

 //This is just a concept not a working script!!!
 
 destroy = false
 animation.playAutomatically = true;
 
 function Update(){
 
     if animation.isPlaying {
 
     }



     else {

     destroy = true;

     }

}

You Could make a function LateUpdate too, could you not?

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AlucardJay · Aug 21, 2012 at 08:33 AM 0
Share

Hopefully your karma will rise soon, and you won't be left waiting for someone to approve your posts =] (think I approved 3 now!)

Just be aware, I did see somewhere before that you may have to wait 1 frame before checking if (animation.isPlaying) , otherwise the object may be destroyed before it gets the Play command (if the Play command is in the same frame as the check if not playing.

Just as a point, even in pseudocode you should include the parenthesis around an if statement. Apart from that, thanks for contributing to the 'site =]

avatar image Panik.Studios · Aug 21, 2012 at 07:21 PM 0
Share

I know right. It's probably better that I don't have $$anonymous$$arma though! I am a complete noob, and shouldn't be trying to answer questions anyway lol. Thanks again for the approval. If it were not for all the trolls on the interweb we wouldn't need systems like this.

avatar image
3

Answer by MathieuBarbier · Aug 21, 2012 at 09:04 AM

You might use animation events. This allow you to call a function based on an animation frame. http://docs.unity3d.com/Documentation/Components/animeditor-AnimationEvents.html

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image neciu · Oct 11, 2014 at 10:25 AM 0
Share

Thank you. This should be the correct answer!

avatar image
2

Answer by MC HALO · Aug 21, 2012 at 08:21 PM

If you want a animation to play just before the object is destroyed then you need it to hold for a sec or the length of the animation. here is what i use now basically the bad guy bob has a health system on him and it decreases every time i shoot him. Once the life reaches 0 he will destroy him self and replace him self with a rigid body. But before the body destroys it plays a animation and then the destroy function is called as well as the apply rigidboady. Here is the script

 var MaxHealth : int = 100;
 var dead: Transform;
 var deadNew: Transform;
 var CurrentHeath : int;
 
 
 function Start () {
 
 CurrentHeath = MaxHealth;
 
 
 }
 
 function ApplyDamage ( Damage : float ) {
 
 
 if( CurrentHeath < 0){
 
 
 return;
 }
 
 CurrentHeath -= Damage;
 
 if( CurrentHeath <= 0 ){
 
 GameObject.Find("Soldier2").animation.Play("CrouchRun");
 Destroytimer ();
 
 }
 
 }
 
 
 function Destroytimer (){
 
    
    yield WaitForSeconds (animation["CrouchRun"].length);
    
      Destroy(gameObject) ;
  
  dead = Instantiate( deadNew, dead.position, dead.transform.rotation);
    
 
 }
 
 
 hope this helps 
  
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Paulo-Henrique025 · Aug 21, 2012 at 08:23 PM 0
Share

Thats it!!

avatar image MC HALO · Aug 21, 2012 at 11:13 PM 0
Share

thats it works like a charm :D

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

12 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

SpriteManager2 and Universal Apps 1 Answer

Sprite Manager 2 Demo 1 Answer

Sprite Manager 2 transparency problem 1 Answer

spritemanager2 1 Answer

iOS Sprite/Texture Recomendations 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges