Hello fellow developers,
I had a problem using GetAxis, maybe I am using it wrong but it doesn’t seem to work because it does not listen to my input.
.
Here is my script:
using UnityEngine;
using System.Collections;
public class SpelerScript : MonoBehaviour
{
//Get animator
private Animator Anim;
void Awake(){
Anim = GetComponent<Animator>();
}
void Update () {
if (Anim.GetBool("isIdle"))
{
Debug.Log("isIdle!");
//Hop forwards
if (Input.GetAxis("Vertical") > 0){
Debug.Log("Hop forward should start");
Anim.SetBool("isIdle",false);
Anim.SetTrigger("hopForward");
}
//Hop backwards
else if (Input.GetAxis("Vertical") < 0){
Debug.Log("Hop back should start");
Anim.SetBool("isIdle",false);
Anim.SetTrigger("hopBack");
}
//Hop right
else if (Input.GetAxis("Horizontal") > 0){
Debug.Log("Hop right should start");
Anim.SetBool("isIdle",false);
Anim.SetTrigger("hopRight");
}
//hop left
else if (Input.GetAxis("Horizontal") < 0){
Debug.Log("Hop left should start");
Anim.SetBool("isIdle",false);
Anim.SetTrigger("hopLeft");
}
}
}
}
this happens because the if statement can’t acces something
Picture of my animator here, every line to one of the 4 animations has it’s own parameter, assigned in the script above, they are named hopBack, hopForward, hopRight, hopLeft. The Idle state in the middle has a behaviour which sets isIdle to true.
You can view the transitions here and here.