(i’m using unity mecanim for the animation controls - version 4.1.5f1)
I have this problem with my script, the problem is that i can’t ask for more than 2 if and else statements.
The only two animation that don’t get enabled is “walk left” and “walk forward”.
I have one script that controls my player movements and THIS script that controls my player animations on input.
Walk “left”, “right” and “forward”, all use the same animation, but there each have their own animation-tree attach to them. walk back have it’s own animation.
(i know that there may be a better way to do this, but i need to know why this don’t work)
i have tryed mixing the variables, to see if there is a problem with the connection to the other animation - trees, but that not it.
(when i did this, “walk back” and “walk forward” don’t get enabled)
according to my debug log, all the lines get executed when i click the keys, so that’s not the problem.
here is the script, if there is someone that can help me, I would be really grateful.
using UnityEngine;
using System.Collections;
public class characterContoller : MonoBehaviour {
private Animator anim; // a reference to the animator on the character
void Start ()
{
// initialising reference variables
anim = GetComponent<Animator>();
}
void Update ()
{
if(anim)
{
if(Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow))
{
anim.SetFloat("Speed", 1f);
Debug.Log("walk forward");
}
else
{
anim.SetFloat("Speed", 0f);
Debug.Log("ready for - walk forward");
}
if(Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
{
anim.SetFloat("Direction", -1f);
Debug.Log("walk left");
}
else
{
anim.SetFloat("Direction", 0f);
Debug.Log("ready for - walk left");
}
if(Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
{
anim.SetFloat("Direction", 1f);
Debug.Log("walk right");
}
else
{
anim.SetFloat("Direction", 0f);
Debug.Log("ready for - walk right");
}
if(Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow))
{
anim.SetFloat("Speed", -1f);
Debug.Log("walk back");
}
else
{
anim.SetFloat("Speed", 0f);
Debug.Log("ready for - walk back");
}
}
}
}