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 raycosantana · Jan 30, 2013 at 09:13 PM · animationwaitforsecondscomplete

Play complete animation

Ive been using co-rutines to do this but it only works when I use GetButton, when I use GetButtonDown (what I actually want to use) it doesnt play the whole animation, it should its like its ignoring WaitForSeconds? it only plays like the first frame.

Please ignore the comments in the code, thats stuff Ive been testing

 using UnityEngine;
 using System.Collections;
 
 public class pistol : MonoBehaviour {
     public GameObject character;
     public Transform Spine;
     
     // Use this for initialization
     void Start () {
     audio.pitch = 2.5f;
     character.animation["shoot_pistol"].AddMixingTransform(Spine,true);
     character.animation["shoot_pistol"].layer = 1;
     //character.animation["shoot_pistol"].speed = 0.4f;
     //character.animation["shoot_pistolidle"].speed = 0.5f;
     }
     
     // Update is called once per frame
     void Update () {
     if (Input.GetButton("Fire1")){
             StartCoroutine(PlayAnimation());
             StartCoroutine(PlaySound());
         }
     else {
             
         
         character.animation.Stop("shoot_pistol");
         character.animation.Stop("shoot_pistolidle");
         }
     }
     IEnumerator PlayAnimation(){
         if (Input.GetAxis("Horizontal")==0){
         character.animation.Play("shoot_pistolidle");
         print ("disparando");
     
         yield return new WaitForSeconds(character.animation["shoot_pistol"].length);
         }
         else {
         //character.animation["shoot_pistol"].time = 0.0F;
             character.animation.Play("shoot_pistol");
         print ("disparando");
         yield return new WaitForSeconds(character.animation["shoot_pistol"].length);
         //character.animation["shoot_pistol"].time = 0.0F;
         //yield return new WaitForSeconds(character.animation["shoot_pistol"].length);
         }
     }
     IEnumerator PlaySound(){
         if (!audio.isPlaying){
         audio.Play();
         yield return new WaitForSeconds(character.animation["shoot_pistol"].length);
          //yield return new WaitForSeconds(0.03f);
         }
     }
 }
 //audio.clip.length

also I would like to know if you have any idea how can I do a snap to frame (animation.time = 0) after I finish the shooting animation and if you dont press Fire1 again in like 5 seconds then go back to the normal walking cycle.

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 whydoidoit · Jan 30, 2013 at 09:15 PM

You problem is that you immediately Stop the animation the next time that Update is called (on the next frame) due to the else on that if in the Update function.

Comment
Add comment · Show 1 · 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 raycosantana · Jan 31, 2013 at 05:24 AM 0
Share

Oops! Im an idiot!, 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

10 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

Related Questions

Animation Window Time Unit 2 Answers

How do I make the animation play once then change scene? 0 Answers

Loop animation with a wait in between 3 Answers

Gun script help 1 Answer

Can the animation editor create local rotational data? 3 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