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 Bazzalisk · Apr 28, 2015 at 06:43 AM · c#animation problem

Switching between animations using if statements bug.

Hey guys, so I've been hitting my head against a wall for a few hours trying to fix this bug. So I have created an animation that goes for 12 seconds to only play once if it hasn't been played before (PlayerPrefs.SetInt ("Animation " + WorldCompleted + " Shown", 1)), then after that animation has finished playing I want it to change to a looping animation. However, when the one time animation finishes playing an all looks good, it then repeats the onetime animation when it should have switched to the looping animation.

 void Start () {
         MeshRendered = GetComponent<MeshRenderer> ();
 
         WorldIsCompleted = PlayerPrefs.GetInt ("World " + WorldCompleted + " Completed");
 
         if (PlayerPrefs.GetInt ("Animation " + WorldCompleted + " Shown") == 0 && WorldIsCompleted == 1)
         {
             print ("1");
             PlayAnimation (0);
             StartCoroutine( Wait ());
         }
         else if (WorldIsCompleted == 1)
         {
             print ("2");
             StartCoroutine (Go ());
         }
         else
         {
             print ("3");
             MeshRendered.enabled = false;
         }
     }
 
     void PlayAnimation(int clip)
     {
         animation.clip = animationClip[clip];
         animation.Play ();        
     }
 
     IEnumerator Wait()
     {
         while(true)
         {
             yield return new WaitForSeconds(12);
             print ("4");
             PlayerPrefs.SetInt ("Animation " + WorldCompleted + " Shown", 1);
             Start ();
             yield return null;
 
         }
     }
 
     IEnumerator Go()
     {
         while(WorldIsCompleted == 1)
         {
             yield return new WaitForSeconds(startDelay);
             startDelay = 0;
             animation.Play ();
             yield return new WaitForSeconds(delayTime);
         }
     }
 }

I've probably missed out on a bunch of important details, so please ask away. Thank you for reading this also sorry about not having line numbers in, I have no idea how to add them.

Bazzalisk

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 dorpeleg · Apr 28, 2015 at 03:07 PM

First, a tip:

store this

 "Animation " + WorldCompleted + " Shown"

in a var and reuse it.

Second, where are you trying to play the looping animation? Is it here:

 animation.Play();

Because that wont work. You need to tell it what animation to play like you are doing here:

 PlayAnimation (0);

I think

 animation.Play();

Plays clip at 0 by default.

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 Bazzalisk · Apr 28, 2015 at 05:38 PM 0
Share

I love you, this worked. 2 days crying is now finished.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Making a bubble level (not a game but work tool) 1 Answer

An OS design issue: File types associated with their appropriate programs 1 Answer

Renderer on object disabled after level reload 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