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 shygeek · Sep 12, 2014 at 09:44 AM · animationgameobjectanimator

How to play the second animation in the animator controller other than the default animation ?

I've two animations(created with Unity animation and animator) in my gui texture. I want to play it with toggle(Toggle code works perfectly fine).The problem is the default animation clip of animator of this gui texture keeps on playing everytime.The second animation clip "ahint2" doesn't play. Please suggest

 function Check(){
 India.gameObject.SetActive(true);
 anim1.SetTrigger("ahint1");
 India.gameObject.animation.Play("ahint1");
 yield WaitForSeconds(India.animation["ahint1"].clip.length);cut = true;
 }
 function Wait(){
 if(cut){
 Debug.Log("enter");
 anim1.SetTrigger("ahint2");
 India.gameObject.animation.Play("ahint2");
 yield WaitForSeconds(India.animation["ahint2"].clip.length);}
 }

Comment
Add comment · Show 1
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 ComeSweetDeath · Sep 12, 2014 at 11:21 AM 0
Share

just to reply to your most recent comment down below: try close the Animator window and restart Unity. That could possibly clear the bug "xx parameter doesn't exist"

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by ComeSweetDeath · Sep 12, 2014 at 10:11 AM

From your script it seems that you're using both Animation and Animator components (the animation.Play part refers to Animation, and anim.SetTrigger("...") refers to Animator). I would first suggest that you stick with either Animation or Animator and avoid using both at the same time since as far as I know they are two systems that handles animation in different ways, and having both of them working at the same time it's possible to get unpredictable behaviour.

Other than that, an obvious suggestions: check if you've turned off "Play Automatically" on your Animation component. If you've unticked that box already but your animation is still not playing the way you want, then maybe you can post your complete animation control script and maybe a screenshot of your animator controller set up so we can better understand your situation.

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 shygeek · Sep 12, 2014 at 10:43 AM 0
Share

Hi, Thanks for the reply.I've already unticked "Play automatically". #

> pragma strict var India : GameObject;
> var bool : boolean = false;
> 
> var anim1 : Animator; var cut :
> boolean = false; private var onoff:
> boolean;   function Start () {
> 
> anim1 = GetComponent(Animator);
> 
> 
> }
> 
> function Update () {     if (bool)  {
>     
>  
>         if (onoff){
>           Check();
>         } else {
>            Wait();
>         }
>     } }
> 
> function Button(){      bool = true; }
> function On$$anonymous$$ouseDown(){ onoff =
> !onoff; } function Check(){
> India.gameObject.SetActive(true);
> 
> 
> anim1.SetBool( anim1.SetBool("one",true); cut = true; > } function Wait(){ > > if(cut) { > > > anim1.SetBool("one",false); > anim1.SetBool("two",true); > > > } }" />

screen shot 2014-09-12 at 4.05.27 pm.png (68.2 kB)
avatar image
0
Wiki

Answer by shygeek · Sep 12, 2014 at 10:44 AM

Hi, Thanks for the reply. Below is my code and attached screenshot. I've already turned off "Play Automatically"

  var India : GameObject;
 var bool : boolean = false;
 
 var anim1 : Animator;
 var cut : boolean = false;
 private var onoff: boolean;
  
 function Start () {
 
 anim1 = GetComponent(Animator);
 
 
 }
 
 function Update () {
     if (bool)  {
     
  
         if (onoff){
           Check();
         } else {
            Wait();
         }
     }
 }
 
 function Button(){
      bool = true;
 }
 function OnMouseDown(){
 onoff = !onoff;
 }
 function Check(){
 India.gameObject.SetActive(true);
 
 
 anim1.SetBool("two",false);
 anim1.SetBool("one",true);
 cut = true;
 }
 function Wait(){
 
 if(cut)
 {
 
 
 anim1.SetBool("one",false);
 anim1.SetBool("two",true);
 
 
 }
 }



[1]: /storage/temp/32351-screen+shot+2014-09-12+at+4.05.27+pm.png


screen shot 2014-09-12 at 4.05.27 pm.png (68.2 kB)
Comment
Add comment · Show 12 · 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 shygeek · Sep 12, 2014 at 10:50 AM 0
Share

Only the first animation is playing on Toggle.

avatar image ComeSweetDeath · Sep 12, 2014 at 11:01 AM 0
Share

by Toggle you mean Loop? Also, when you play the game, are there any warning errors? If there are, what are the errors saying?

 var India : GameObject;
 var bool : boolean = false;
 var cut : boolean = false;
 var anim1 : Animator;
 var onoff: boolean;
  
 function Start () { 
     anim1 = GetComponent(Animator); 
 }
 
 function Update () {
     if (onoff) {
         Check();
     }
     else {
         Wait();
     }
 }
 
 function On$$anonymous$$ouseDown(){
     onoff = !onoff;
 }
 
 function Check(){
     India.gameObject.SetActive(true);     
     anim1.SetBool("two",false);
     anim1.SetBool("one",true);
     cut = true;
 }
 
 function Wait(){     
     if(cut)    {     
         anim1.SetBool("one",false);
         anim1.SetBool("two",true); 
     }
 }


Give this script a try

avatar image shygeek · Sep 12, 2014 at 11:06 AM 0
Share

alt text

screen shot 2014-09-12 at 4.35.09 pm.png (31.3 kB)
avatar image shygeek · Sep 12, 2014 at 11:06 AM 0
Share

There are no errors

avatar image shygeek · Sep 12, 2014 at 11:10 AM 0
Share

alt text

screen shot 2014-09-12 at 4.40.09 pm.png (42.2 kB)
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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Keyframes of animated Child gameobject not shown by parent gameobjects animator issue ? 0 Answers

Best way to - Animation Sync - Multiple gameObjects. 0 Answers

Best Way - Animation - Multiple GameObjects. 0 Answers

changing a game object with another 0 Answers

Object's sprite and collider are not at same position as transform 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