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
1
Question by user-3061 (yahoo) · Dec 17, 2010 at 12:36 AM · animationjavascriptwaitforsecondsreload

Make the animation play at the start of the time waited, not the end of it?

I'm working on an FPS gun script, and i took the "reload" function from the script in the FPS tutotrial.

function Reload () {

 yield WaitForSeconds(reloadTime);

 if (clips > 0) {
     clips--;
     bulletsLeft = bulletsPerClip;
 }

}

I added animation.Play like this:

function Reload () {

 yield WaitForSeconds(reloadTime);

 if (clips > 0) {
     clips--;
     bulletsLeft = bulletsPerClip;
     animation.Play ("Reload");    // Line added.
 }

}

The problem is that it plays the animation after the "WaitForSeconds". What should I do to make the animation play within the time span?

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
1
Best Answer

Answer by Statement · Dec 17, 2010 at 12:55 AM

Move the wait to after the animation starts. You probably also want to have it inside the clips test, and update bullets left after the wait is over.

function Reload () {    
    if (clips > 0) {
        clips--;
        animation.Play ("Reload");
        yield WaitForSeconds(reloadTime);
        bulletsLeft = bulletsPerClip;
    }
}


If it would help you understand the flow of code, let's break down the Reload function into smaller parts:

function Reload () { if (clips > 0) { BeginReload(); yield WaitForSeconds(reloadTime); EndReload(); } }

function BeginReload () { clips--; animation.Play("Reload"); }

function EndReload () { bulletsLeft = bulletsPerClip; }

Comment
Add comment · Show 4 · 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 user-3061 (yahoo) · Dec 17, 2010 at 02:36 AM 0
Share

actually i tried that before,but the scripts still wont work.. the waiting part functions correctly, but it wont play the animation...

avatar image Statement · Dec 17, 2010 at 02:43 AM 0
Share

But you wrote: "The problem is that it plays the animation after the WaitForSeconds". $$anonymous$$ake sure the object has an animation and the animation has a clip called "Reload".

avatar image user-3061 (yahoo) · Dec 17, 2010 at 02:54 AM 0
Share

yes it has a clip named reload, im very sure

avatar image user-3061 (yahoo) · Dec 17, 2010 at 03:21 AM 0
Share

Okay, i got it working now (partially), but your answer is correct, it was some other animation's problem. Thanks!

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

No one has followed this question yet.

Related Questions

Punch Animation Doesn't Work And Others Do... 1 Answer

Animation play when dead 2 Answers

Java Script: Clock script help. 1 Answer

Animation Script not working. 1 Answer

Animation Script Error 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