i set up a movement script with animations. The animations work when i go left or right or if i jump. But when jumping if im mid air i cant move left or right. If i right first and then jump it jumps to the right but i cant jump first and THEN move. How do i fix this?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public ImprovedMovement controller;
float horizontalMove = 0f;
public float runSpeed = 40f;
bool Jump = false;
bool Crouch = false;
public Animator animator;
// Update is called once per frame
void Update()
{
horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;
animator.SetFloat("speed", Mathf.Abs(horizontalMove));
if (Input.GetButtonDown("Jump"))
{
Jump = true;
animator.SetBool("isjumping", true);
}
if (Input.GetButtonDown("Crouch"))
{
Crouch = true;
} else if (Input.GetButtonUp("Crouch"))
{
Crouch = false;
}
}
public void OnLanding()
{
animator.SetBool("isjumping", false);
}
void FixedUpdate ()
{
//movement
controller.Move(horizontalMove * Time.fixedDeltaTime, Crouch, Jump);
Jump = false;
}
}