using Unity.VisualScripting; using UnityEngine; using UnityEngine.InputSystem; public class BallController : MonoBehaviour { private float ballSpeed; private float brakeForce; private float jumpForce; private Rigidbody rb; float outOfBounds = -1.8f; public void Start() { rb = GetComponent(); ballSpeed = 3f; brakeForce = 0.3f; jumpForce = 14f; } private void Update() { KeyHandler(); CheckPlayerOut(); } void CheckPlayerOut() { if (transform.position.y < outOfBounds) { transform.position = new Vector3(0, 1f, 0); transform.rotation = Quaternion.Euler(0, 0, 0); } } public void KeyHandler() { if (Keyboard.current.wKey.isPressed) { rb.AddForce(Vector3.forward * ballSpeed); } else if (Keyboard.current.sKey.isPressed) { rb.AddForce(Vector3.back * ballSpeed); } else if (Keyboard.current.dKey.isPressed) { rb.AddForce(Vector3.right * ballSpeed); } else if (Keyboard.current.aKey.isPressed) { rb.AddForce(Vector3.left * ballSpeed); } if (Keyboard.current.spaceKey.isPressed && transform.position.y < 1) { Debug.Log("KrossKross will make you..."); rb.AddForce(Vector3.up * jumpForce); } else { rb.AddForce(-rb.linearVelocity * brakeForce); } } }