- Home /
I'm confused with the animator
So I've got multiple animations and if I press the right button it would transform from Idle State to Right. So here's my script;
private var speed : float = 3;
private var speed2 : float;
var character : GameObject;
var isBack : boolean;
var isLeft : boolean;
var isRight : boolean;
var isIdle : boolean;
var isFront : boolean;
var Animator : Animator;
private var hit : RaycastHit2D;
function Update () {
BlahBlah ();
if(Input.GetMouseButtonDown(0)) {
hit = Physics2D.Raycast(camera.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
if( hit.collider.gameObject.name == "Right")
{
speed2 = 1;
Debug.Log("Clicked");
isRight = true;
Animator.SetBool("isRight", isRight);
Animator.SetFloat("speed", speed2);
BlahBlah ();
}
}
if(Input.GetMouseButtonUp(0)) {
isRight = false;
isIdle = true;
speed2 = 0;
}
}
function BlahBlah () {
if(isRight == true) {
character.transform.position.x = character.transform.position.x += 1.25 *(speed * Time.deltaTime);
}
}
So in the animator, I've set the condition of the transition from right to idle to *isIdle is true *isRight is false *speed is less than 0.01
but when I released the button it would stop moving along the x axis but it would continue to play the Right animation instead of transitioning to Idle. I don't know whats wrong with this scriptt here.
Edit: Found the answer(By myself) it was because I didn't sign the isIdle variable boolean to the animator boolean. I forgot to put Animator.SetBool ("isIdle", isIdle)
put your code part
Animator.SetBool("isRight", isRight);
Animator.SetFloat("speed", speed2);
outside Button Down and inside Update
Nope, didn't work, still the same @$$anonymous$$ayank Ghanshala
I don't find any pictures that could help me but do you know the answer? @Linus
try rena$$anonymous$$g your animator component. I think Animator as Animator is causing issues. try
var anim: Animator;
I know for a fact that na$$anonymous$$g convention works because i use it all the time.
anim.SetBool("isRight", isRight);
Answer by tanoshimi · Nov 08, 2014 at 09:33 AM
In your if(Input.GetMouseButtonUp(0)) {}
, you don't ever set the Animator conditions again. I suspect you meant something like:
if(Input.GetMouseButtonUp(0)) {
isRight = false;
isIdle = true;
speed2 = 0;
Animator.SetBool("isRight", isRight);
Animator.SetFloat("speed", speed2);
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Setting Scroll View Width GUILayout 1 Answer
2D Animation Effects Velocity Wrong? 0 Answers