- Home /
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);}
}
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"
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.
Hi, Thanks for the reply.I've already unticked "Play automatically". #
anim1.SetBool("one",true); cut = true; > } function Wait(){ > > if(cut) { > > > anim1.SetBool("one",false); > anim1.SetBool("two",true); > > > } }" />
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
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
Your answer
Follow this Question
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