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 Mrroundtree22 · May 01, 2021 at 12:25 AM · animationcoroutineswitch

Coroutine / Switch case

Animator anim; int inputNum;

 public IEnumerator PlayAnims()
 {
     switch (inputNum)
     {
         case 1:
             anim.Play("1");
             Debug.Log("1");
             yield return new WaitForSeconds(1);
             break;
         case 2:
             anim.Play("2");
             Debug.Log("2");
             yield return new WaitForSeconds(1);
             break;
         case 3:
             anim.Play("3");
             Debug.Log("3");
             yield return new WaitForSeconds(1);
             break;
     }
 }

So the idea is that it should only play one animation at a time for 1 second then play the next one for 1 second etc. If it gets multiple inputs at once it picks the one which was first, like a queue, so if the input is 2,1,2,3 then they play those animations in that order 1 second at a time before the next animation starts.

Comment
Add comment · Show 2
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 HellsHand · May 01, 2021 at 02:25 PM 0
Share

Not easy to answer when we don't know how this Coroutine is being called or how inputNum is being set.

avatar image Mrroundtree22 HellsHand · May 01, 2021 at 02:50 PM 0
Share

Yes I understand that. I'm just not sure how to explain it. You would type in the input so if you type in 2223 then the second animation would play three times after another and then the third animation last. So the StartCoroutine would contain the inputNum.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by HellsHand · May 01, 2021 at 04:30 PM

Ok lemme put it this way. Nothing in your Coroutine allows for anything more than one animation to play. If you try to stick it in a loop and call it for each value, all animations would technically be called at the same time not 1 each second since a loop completes in it's entirety in 1 single frame and there can be multiple Coroutines running at the same time. That said if the loop were inside the Coroutine that would be a different story. Such as:

 public IEnumerator PlayAnims(string inputString)
 {
     char[] inputs = inputString.ToCharArray();

     foreach (char inputNum in inputs)
     {
         switch (int.Parse(inputNum.ToString()))
         {
             case 1:
                 anim.Play("1");
                 Debug.Log("1");
                 yield return new WaitForSeconds(1);
                 break;
             case 2:
                 anim.Play("2");
                 Debug.Log("2");
                 yield return new WaitForSeconds(1);
                 break;
             case 3:
                 anim.Play("3");
                 Debug.Log("3");
                 yield return new WaitForSeconds(1);
                 break;
         }
     }
 }
Comment
Add comment · Show 10 · 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 Mrroundtree22 · May 01, 2021 at 07:17 PM 0
Share

I want only one animation to play. But I want to input my numbers, the animation correspondent to the first number play, waitForSeconds, then play the next one. I.e if I type in "2, 2, 3, 1" I want animation 2 to play, wait, then play 2 again, wait, then 3, wait, then 1.

avatar image HellsHand Mrroundtree22 · May 01, 2021 at 07:37 PM 0
Share

That is what the code provided does, it takes a string of digits(you would have to ensure they are digits though) and calls the case corresponding to the first digit, waits for 1 second, calls the next case that corresponds with the next digit, waits for a second and so on. If this isn't what your asking for you may need to provide further information. First question that comes to $$anonymous$$d is are all these animations a second long? If not does it need to wait for the current animation to finish before calling on the next(though I guess it should)?

avatar image Mrroundtree22 HellsHand · May 01, 2021 at 09:16 PM 0
Share

What happens is that it plays the animations but not in the right order. So if I press 2,2,3 it plays it back as 2, 3, 2. If I press 2,1,1,1 it plays it back as 2,1,2,1. Do you know why?

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

295 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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

Mechainm Animation to Ragdoll 1 Answer

How to prevent holding down a key to infinitely loop an action? 1 Answer

Switch holding hand when reload weapon 1 Answer

Can the animation editor create local rotational data? 3 Answers

Instantly switch animation 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