Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 Uping · Feb 15, 2014 at 08:05 AM · animationtimecomponentdisablehow-to

how to make my component disabled after an animation

i already done it my problem is the component is being disabled before the animation is done i have separate scripts by the way so here's the code

here's the first code this code is for the animation for my character

 private void HandleAnswer(int answer) {
                         
                             if (answer == 1)
             
                         {
                             //handle correct answer
                             ShowIncorrect = false;
                             ShowCorrect = true;
                             Poop = false;
         
                            animation.PlayQueued ("Wrong answer",QueueMode.PlayNow);  
                             Enemy.animation.PlayQueued("ENMattck", QueueMode.CompleteOthers);
                             Attack();
                             NextQuestion();
 
                         }                                
                             else { 
             
                             ShowIncorrect = true;
                              ShowCorrect = false;
                             Poop = false;
 
                             animation.PlayQueued ("Wrong answer",QueueMode.PlayNow);  
                             Enemy.animation.PlayQueued("ENMattck", QueueMode.CompleteOthers);
 
                             AttackSelf();            
                         }        

here's the second code for my enemy which tells that if the enemy health is 0 the enemy will be disabled but what happens is after i push a certain button for the animation the enemy is disabled so i need a timer or something so that until the animation is done my component wont be disabled

     void Update () {
         
         if (curHealth <= 0) {    
             
              PlayerPrefs.SetInt("SavedLevel1", 1);
             Debug.Log("SavedLevel = 1");        
         
                 Enemy.gameObject.SetActive(false);
          
 }

             
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by RedDevil · Feb 15, 2014 at 08:16 AM

A timer would be

yield return new WaitForSeconds(amountoftime); But if you do this you would have to declare the Update function as an IENumerator and this is not allowed. I sugest you do it like this:

  if (curHealth <= 0) { 
  StartCoroutine(ObjectActive());
                    }
 IENumerator ObjectActive() {

PlayerPrefs.SetInt("SavedLevel1",1);

Debug.Log("SavedLevel = 1");

yield return new WaitForSeconds(2);

Enemy.gameObject.SetActive(false);

}

Comment
Add comment · Show 7 · 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 Uping · Feb 15, 2014 at 09:33 AM 0
Share

thank you very much you really help me.

by the way its not part of the topic but can you help me with this one its also about animation what happens is after my enemy dies, a first animation should play witch is the attack animation and the second one is after that animation so here's the code

     void Update () {
                     if(!Enemy.animation.IsPlaying("EN$$anonymous$$attck")){
                         if(!animation.IsPlaying("Wrong answer")){
         
                 
                             if (EH.curHealth <= 0) {                
                             Poop=false;    
                             ShowCorrect = false;
                             ShowIncorrect = false;
                         animation.Play("Next_Enemy");
                     
                 }

so i did it but what happens is after my first animation play's the second one plays but the second one will keeps on repeating itself, can you help me ? but if not, its okay its not part of my question anyway thankyou

avatar image RedDevil · Feb 15, 2014 at 10:01 AM 0
Share

you should check on the animation if its set to loop.If its not then its because the Cur Health if constantly getting called since you got no more Health.

avatar image Uping · Feb 15, 2014 at 10:05 AM 0
Share

nope its not, i think its because i put it on update function but if i dont put it there it wont work, is there anything else i can do...

avatar image RedDevil · Feb 15, 2014 at 10:07 AM 0
Share

if this animation is for the enemy that will die then you can just destroy the game object after he played the animation

avatar image Uping · Feb 15, 2014 at 11:19 AM 0
Share

if you destroyed the gameobject errors will occur thats why i just disabled the components.

Show more comments

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.

Follow this Question

Answers Answers and Comments

19 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to disable an certain animation from my player? 0 Answers

2D Animation does not start 1 Answer

timer that can be reset 1 Answer

How to achieve squash and stretch on characters similar to 3D Mario games 0 Answers

Can I make animations snap to a frame? 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