So I want my player to walk forward and sideways with walking animations and was wondering about where should I place this code so that it can function with no errors. Keep in mind that my player can walk forward and sideways, but remains in idle animation. I made a blendtree with the walking animations in the animator scene.
code below:
public class Player : MonoBehaviour { public Transform aimTarget; public Animator anim;
float speed = 3f;
float force = 13;
bool hitting;
void Update()
{
float h = Input.GetAxisRaw("Horizontal");
float v = Input.GetAxisRaw("Vertical");
if(Input.GetKeyDown(KeyCode.F))
{
hitting = true;
}else if (Input.GetKeyUp(KeyCode.F))
{
hitting = false;
}
if (hitting)
{
aimTarget.Translate(new Vector3(h, 0, 0) * speed * Time.deltaTime);
}
The 2nd code below is the code that I want to paste with the code above, but don’t know where to paste it after void update, float sections. This is where the errors start to occur.
public Animator anim;
// Update is called once per frame
void Update()
{
anim.Setfloat("vertical", Input.GetAxis("Verical"));
anim.Setfloat("Horizontal", Input.GetAxis("Horizontal"));
}
Any help would be appreciated.