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 reltuc · Jun 26, 2012 at 10:52 PM · yieldwaitforseconds2d animation

Yield causing 2D animation to pause

I'm having trouble getting my 2d animation to play properly. I have a character that has an idle animation, I've made it so that when you click on the character the animation changes to something else. I want it to play all of the frames of the animation (when clicked) and then return to it's idle state when the animation is finished, however i've tried using a yield WaitForSeconds at the length of the animation but this stops it from playing as though it's been paused, which I guess it kinda has. it freezes on the frame that the yield became active. I'm working with the animation code from the walker boys 2d mario tutorial which calls the frames in sequence in the code. I understand that Yield basically stops the code and thus stops my animation from playing the next frame. So i'm wondering if there is another way that I can wait a few seconds for my animation to finish before I switch back to the idle state.

Cheers.

Here's the code that I'm working with:

if (idle) {

   aniPlay.aniSprite ( 8, 8, 0, 0, 16, 24 );
  }


if (clicked){

 aniPlay.aniSprite ( 8, 8, 0, 4, 16, 24 );
 
 yield WaitForSeconds ( 5);
     clicked = false;
     idle = true;
     

 }


if (Input.GetMouseButtonDown(0) ) {

if(Physics.Raycast(ray,hit,100.0)) {

         if(hit.transform.tag == "character"){
         
         idle = false;
         clicked = true;
         }            

}

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

Answer by pheash · Jun 26, 2012 at 10:58 PM

heya, you could simply introduce a timer. store the game time into a variable when clicked turns to true and then have a conditional that checks if the game time is bigger than the stored time + an offset. eg:

 var timeClicked;
 
 // this goes into your raycast bit:
 timeClicked = Time.time;
 // this goes into your update function inside the if(clicked)
 if(Time.time > timeClicked+5.0){clicked = false; idle = true;} // instead of using 5.0 create a variable waitTime and set it to the length of your animation..

hope that helps a bit.

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 reltuc · Jun 27, 2012 at 08:31 PM 0
Share

That's great, just what I needed. Thanks a lot Pheash!

avatar image pheash · Jul 24, 2012 at 09:52 AM 0
Share

np. could you mark the question as answered to keep the forums clean?

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

no "pointers" to get directly to a variable passed to a function? 1 Answer

Getting an error when trying to yield 2 Answers

is there any function call will be call after i activate an object ? 1 Answer

Why does Yield WaitForSeconds () only run once 1 Answer

Yield WaitForSeconds outside of time.Scale 7 Answers


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