using UnityEngine; public class Player : MonoBehaviour { private CharacterController character; private Vector3 direction; public float gravity = 9.81f * 2f; public float jumpForce = 8f; private void Awake() { character = GetComponent(); } private void OnEnable() { direction = Vector3.zero; } private void Update() { direction += Vector3.down * gravity * Time.deltaTime; if (character.isGrounded) { direction = Vector3.down; if (Input.GetButton("Jump") || jumpQueued) { direction = Vector3.up * jumpForce; jumpQueued = false; } } character.Move(direction * Time.deltaTime); } bool jumpQueued = false; public void Jump(){ jumpQueued = true; } private void OnTriggerEnter(Collider other) { if (other.CompareTag("Obstacle")) { GameManager.Instance.GameOver(); } } }