This is a pretty simple jumping script,
void onUpdate() {
if (Input.GetButtonDown("Jump") && onGround)
rigidbody.velocity += new Vector3(0, jumpVelocity/50, 0);
}
void OnCollisionStay(Collision collision) {
foreach (ContactPoint contact in collision.contacts)
if (Vector3.Angle(contact.normal, Vector3.up) < maxSlope)
onGround = true;
}
void OnCollisionExit (Collision collision) {
onGround = false;
}
but you see the problem is that when the object (let’s say floor) gets destroyed and there are no other colliders, OnCollisionExit is not triggered and OnCollisionStay also stops functioning. In which case my player can still jump infinitely many times until I hit a floor.
I wonder if there is maybe a way to know if a player does or does not collide with anything at all. That would solve my problem.