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 asdf123 · Jan 09, 2014 at 08:01 PM · animationcoroutinemecanimienumerator

Mecanim animation, playing once

I really hate the mecanim animation system, i can't simply do animation.play("blabla"); i need to do a lot of things just to play an animation lol.

so, i'm here to ask someone how i can play an animation just once, i press a button, and it just play ONCE the animation. i've tryed that:

 public Animator weaponAnim;
 
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
 
         if (Input.GetButtonDown ("Fire1")) {
             StartCoroutine("Shoot");
         }
 
     }
 
     public IEnumerator Shoot () {
         
         weaponAnim.SetBool("inShoot", true);
 
         yield return new WaitForSeconds (weaponAnim["Shoot"].lenght);
         
         weaponAnim.SetBool("inShoot", false);
         
     }


and another thing i need is: how can i get an animation lenght? i used weaponAnim["blabla"].lenght, but it gives me errors.

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 SinisterRainbow · Jan 09, 2014 at 08:56 PM

Main Question: In the Project folder, find the animation, and make sure it's NOT set to looping. Once you remember a few basic things to check for the animation system, it's cake. I made a game with custom animations in a 48 hour game jam recently, would never use anything but Unity to attempt this.

"Another thing": animation["ani-name"].length is the correct way to do it. Post a new question with the error messages so someone else can solve it...

Both might be solved by setting up the animation properties properly in the Project folder, i suspect that's where ure main problem lies.

Comment
Add comment · Show 3 · 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 asdf123 · Jan 09, 2014 at 09:58 PM 0
Share
 public Animator weaponAnim;
 
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
 
         if (Input.GetButtonDown ("Fire1")) {
             StartCoroutine("Shoot");
         }
 
     }
 
     public IEnumerator Shoot () {
         
         weaponAnim.SetBool("isShoot", true);
         weaponAnim.SetBool("isIdle", false);
 
         yield return null;
         
         weaponAnim.SetBool("isShoot", false);
         weaponAnim.SetBool("isIdle", true);
         
     }

i have this, but now the shoot animation just play 50% of it

avatar image SinisterRainbow · Jan 09, 2014 at 10:32 PM 0
Share

you're only delaying 1 frame before setting shoot to false - that's either the fastest animation ever, or you need to delay longer. :) This is also not the best way to approach animation. You probably want to think about how animations interact with one another. for 2-3 animations something simple is adequate, but on larger systems you likely will want some to crossfade, some animations should wait to finish first, etc..

avatar image JanusHuang · Jan 14, 2014 at 09:10 AM 2
Share

If you are using Unity 4.3, you can use Animator.SetTrigger("ParameterName") ins$$anonymous$$d of setting true and false.

Unity Reference:

"Triggers are parameters that act mostly like booleans, but get resets to inactive when they are used in a transition."

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

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

Related Questions

beguin (but not wait for) the smoothing of a float in coroutine 1 Answer

Yield Wait for Seconds (A little help here) 2 Answers

Line of code skips randomly at times? 1 Answer

AnimationCurve as fixed time rather than portion of time? 1 Answer

Play animation then destroy gameOject C# "SOLVED" 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