Hi there, I’m making a 2d game in unity. As far as im aware, i have made my code correctly but My character won’t jump when i click space
This is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public CharacterController2D controller;
public float runSpeed = 1000f;
float horizontalMove = 0f;
bool Jump = false;
bool Crouch = false;
// Update is called once per frame
void Update()
{
horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;
if (Input.GetKeyDown(KeyCode.Space))
{
Jump = true;
}
if (Input.GetKeyDown(KeyCode.LeftControl))
{
Crouch = true;
} else if (Input.GetKeyUp(KeyCode.LeftControl))
{
Crouch = false;
}
}
void FixedUpdate()
{
// move the character
controller.Move(horizontalMove * Time.fixedDeltaTime, Crouch, Jump);
Jump = false;
}
}
This is a screenshot of what i have in unity
note: I dont want the character to be able to be controlled in the air so thats why air control is off
