The On Ground check box won't stay checked. Every time I jump once it automatically turns off. After exporting it and playing it my character is only able to jump once. Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; public class Jump : MonoBehaviour{ public bool onGround; private Rigidbody rb; void Start () { onGround = true; rb = GetComponent<Rigidbody> (); } void Update() { if(onGround) { if(Input.GetButtonDown("Jump")) { rb.velocity = new Vector3 (0f, 7f, 0f); onGround = false; } } } void OnCollisionEnter(Collision other) { if(other.gameObject.CompareTag("ground")) { onGround = true; } } }
Your ground has to have a collider on it, and your character has to have a collider as well as the rigidbody it appears to already have.
You're never getting an OnCollisionEnter message where the thing you're colliding with has the tag "ground". You should add a debug message to your OnCollisionEnter to see what's going on: Code (csharp): void OnCollisionEnter(Collision other) { Debug.Log("Collided with " + other.gameObject.name + ", which has the tag " + other.gameObject.tag, other.gameObject); if(other.gameObject.CompareTag("ground")) { onGround = true; } } Since I added other.gameObject as the second argument to Debug.Log, you can click the log message to get the thing you're collided with pinged in the hierarchy.
My guess is you have spelled the "ground" tag wrong in your comparison in OnCollisionEnter. Maybe you spelled it "Ground" or something.