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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by IKilledKenny_2 · Oct 15, 2014 at 05:47 AM · animation

wait until an animation finishes

Hello Unity3D i have a question about animation.How can i make it that when i do an animation you can't do anything else until animation is finished?For example,when i make my character throw a projectile the idle animation that plays waits for it to finish but when i click the movement keys like up,down,left,right the character still moves.How can i make it that the character plays an animation and you can't do nothing to stop it until the animation is completely finished?

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 zharik86 · Oct 15, 2014 at 06:08 AM

Use coroutine and bool variable. Idle and Walk animation is loop(write on CSharp):

  private bool state = false;
  private bool change = false;
  private string curAnim = "";

  void Update() {
   //play idle
   if (Input.GetKeyDown(KeyCode.I)) {
    if(curAnim != "Idle") {
     curAnim = "Idle";
     change = true;
    }
   }
   if (Input.GetKeyDown(KeyCode.T)) {
    if(curAnim != "Walk") {
     curAnim = "Walk";
     change = true;
    }
   }
   if(change && !state) {
    this.animation.Play(curAnim);
    this.StartCoroutine(this.myPlay(curAnim));
   }
  }

  public IEnumerator myPlay(string tpAnim) {
   curAnim = tpAnim;
   while(!change) {
    state = true;
    yield return new WaitForSeconds(this.animation.clip.length);
    state = false;
   }
  }

I hope that it will help you.

Comment
Add comment · Show 6 · 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 IKilledKenny_2 · Oct 15, 2014 at 05:28 PM 0
Share

Thanks for the script ill convert it to javascript right now.

avatar image zharik86 · Oct 15, 2014 at 06:13 PM 0
Share

@tokenten Write your comment as comment, not answer. For comment, press button "Add new comment" below answer. If you need help to transfer in Java, just write here.

And if I or everybody help you, than mark rigth answer.

avatar image IKilledKenny_2 · Oct 15, 2014 at 08:58 PM 0
Share

Oh sorry i haven't been here in a while so i kind of forgot...Also you can help me with writing the script in java?

avatar image zharik86 · Oct 16, 2014 at 07:03 AM 0
Share

@tokenten I transfer my script in Java. And I hope that it will help you further most to transfer one program$$anonymous$$g language to another. As the transfer in other program$$anonymous$$g language not such rare task:

  private var state: boolean = false;
  private var change: boolean = false;
  private var curAnim: String = "";
 
  function Update() {
   //play idle
   if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.I)) {
    if(curAnim != "Idle") {
     curAnim = "Idle";
     change = true;
    }
   }
   if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.T)) {
    if(curAnim != "Walk") {
     curAnim = "Walk";
     change = true;
    }
   }
   if(change && !state) {
    this.animation.Play(curAnim);
    this.StartCoroutine(this.myPlay(curAnim));
   }
  }
 
  function myPlay(string tpAnim) {
   curAnim = tpAnim;
   while(!change) {
    state = true;
    yield WaitForSeconds(this.animation.clip.length);
    state = false;
   }
  }

That's all. I hope that works.

avatar image IKilledKenny_2 · Oct 16, 2014 at 05:07 PM 0
Share

Thank You! So $$anonymous$$uch!!!!

Show more comments

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

2 People are following this question.

avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

Blender Animation Looping Delay Problem 2 Answers

SpriteManager 2 1 Answer

Making a Tiled Animated Image With a Material 0 Answers

How to get a animation to play without changing the pozition the gun is in when aming down sights 0 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