I’m making a game in Unity 3D and I have this script attached to my player to make him jump when the Up arrow is pressed:
private Rigidbody rb;
public float jumpForce;
void Start()
{
rb = gameObject.GetComponent<Rigidbody>();
anim = gameObject.GetComponent<Animator>();
}
void Update()
{
PlayerMovement();
Jump();
}
void Jump()
{
if (Input.GetKeyDown(KeyCode.UpArrow))
{
Debug.Log("This if works");
rb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
}
}
My player has a rigidbody attached to it and I know the if statement works because of that debug.log, however, nothing happens when I press the up arrow. Anyone know why? Let me know if you need any more info about the script or the player object. Thanks for your help!