Hello, im really new to unity and i tried to get my 2d object to jump. But after the first jump it wont jump again. Does anybody have a solution tho this?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class JumpScript: MonoBehaviour
{
public Vector3 jump;
public float jumpForce = 2.0f;
public bool isGrounded;
Rigidbody2D rb;
void Start()
{
rb = GetComponent<Rigidbody2D>();
jump = new Vector3(0.0f, 2.0f, 0.0f);
}
void OnCollisionStay()
{
isGrounded = true;
}
void OnCollisionExit()
{
isGrounded = false;
}
void Update()
{
if (Input.GetKeyDown(KeyCode.UpArrow) && isGrounded)
{
rb.AddForce(jump * jumpForce, ForceMode2D.Impulse);
isGrounded = false;
}
}
}