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 juniperspark · Jan 24, 2015 at 08:40 PM · animationuiwaitforsecondsswitchslow

script runs fine on start up, but slows on second attempt

Hi,

I wondered if anyone could solve this for me? I have this script that runs perfect the first time I click play on the editor, but when it's completed it's cycle and I click the button again, it pauses for a bit. There is a loose, non-functional version of my code below.

I'm wondering if it's anything to do with turning the button off or the waitforseconds();. There is no stuttering at all, the animations play fine, they bob along in idle while waiting for the button to turn back on. It only turns on immediately after the attack when I turn off the editor and back on. If I do the cycle twice, it will pause before turning the buttons back on.

 function ButtonStart()                    
 {
     currentState = State.PlayerTurn;
     TurnOffButton();
     StateManager();        
 }
 
 
 function StateManager()
 {                
     switch(currentState)
     {
         case State.PlayerTurn:
         PlayerTurn();
         break;
         
         case State.EnemyTurn:
         EnemyTurn();
         break;
         
         case State.Attack:
         Attack();
         break;
         
         case State.SwitchTurn:
         Switch();
         break;
         
         default:
         break;
     }
 }
 
 function PlayerTurn ()
 {
     // sets player meshes & tags
     Attack();
 }
 
 function EnemyTurn ()
 {
     // sets enemy meshes & tags
     Attack();
 }
 
 function Switch ()
 {
     // if turn is players then change turn to Enemy turn
     // if turn is enemys then change turn to player turn
     && TurnOnButton();
 }
 
 function Attack ()
 {
         attacker.animation.Play("attack"); 
         attacker.animation.PlayQueued("idle");
         yield WaitForSeconds (attacker.animation["attack"].length + 0.2);
         //Normal Damage Calculation
         defender.animation.Play("takeDamage");
         defender.animation.PlayQueued("idle");
         yield WaitForSeconds (defender.animation["takeDamage"].length + 0.2);            
         text.text = "Dealt " + Damage + " damage!";
         currentState = State.SwitchTurn;
         StateManager();
 }
 
 TurnOffButton ()
 {
     button.interactable = false;
 }
 
 TurnOnButton ()
 {
     button.interactable = true;
 }
 

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 TheFattestNinja · Jan 26, 2015 at 04:36 PM 0
Share

$$anonymous$$aybe the fix I found for a similar issue I had (posted here) can help you?

1 Reply

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

Answer by juniperspark · Jan 31, 2015 at 05:16 PM

Hi there!

I found the problem! As i'd edited the code to be a stripped down version, I'd left out the part that was causing me problems, which was stupidly the Debug.Log. If I removed this from my script, it worked! Thanks!

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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Button animator not playing. 0 Answers

Unity web player slow response to first interaction 1 Answer

Unity 5.2 Canvas.RenderOverlays serious fps hit 2 Answers

Unity UI slow?(WaitingForJob and Canvas.RenderOverlays related problem) 1 Answer

Replacing animations from a list at runtime 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