- Home /
Question by
DJGarbage · Mar 01, 2021 at 12:22 PM ·
animator controllerboolbooleanswasd
Simple controller is not so simple,Trying to animate with Bools
I'm struggling to get this script to run, I would really appreciate the help, this is my first script for animating the legs of my character, what am I doing wrong? I'm trying to set bools to false/positive with getkeydown and getkeyup for idle, walking forward, walking back, left, and right.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class walk1 : MonoBehaviour {
public Animator anim;
// Use this for initialization
void Start()
{
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{ if (Input.GetKeyDown(KeyCode.W)) { anim.SetBool("forward", true);
}
if (Input.GetKeyDown(KeyCode.A))
{
anim.SetBool("left", true);
}
if (Input.GetKeyDown(KeyCode.S))
{
anim.SetBool("back", true);
}
if (Input.GetKeyDown(KeyCode.D))
{
anim.SetBool("right", true);
}
if (Input.GetKeyUp(KeyCode.W))
if (Input.GetKeyUp(KeyCode.A))
if (Input.GetKeyUp(KeyCode.S))
if (Input.GetKeyUp(KeyCode.D))
{
anim.SetBool("idle", true);
}
}
Comment
Answer by $$anonymous$$ · Mar 02, 2021 at 02:12 AM
float horizontal = Input.GetAxis("Horizontal");
float vertical = Input.GetAxis("Vertical");
anim.SetFloat("Horizontal", horizontal);
anim.SetFloat("Vertical", vertical );
Check this links out to see how to setup the animator controller.