Ändrade public till private

This commit is contained in:
2026-03-25 16:56:15 +01:00
parent eec02413cc
commit 6347eca15e

View File

@@ -1,22 +1,21 @@
using Unity.VisualScripting;
using UnityEngine; using UnityEngine;
using UnityEngine.InputSystem; using UnityEngine.InputSystem;
public class BallController : MonoBehaviour { public class BallController : MonoBehaviour {
private float ballSpeed; float _ballSpeed;
private float brakeForce; float _brakeForce;
private float jumpForce; float _jumpForce;
private Rigidbody rb; Rigidbody _ball;
float outOfBounds = -1.8f; float outOfBounds = -1.8f;
public void Start() { void Start() {
rb = GetComponent<Rigidbody>(); _ball = GetComponent<Rigidbody>();
ballSpeed = 3f; _ballSpeed = 3f;
brakeForce = 0.3f; _brakeForce = 0.3f;
jumpForce = 14f; _jumpForce = 14f;
} }
private void Update() { void Update() {
KeyHandler(); KeyHandler();
CheckPlayerOut(); CheckPlayerOut();
} }
@@ -28,25 +27,24 @@ public class BallController : MonoBehaviour {
} }
} }
public void KeyHandler() { void KeyHandler() {
if (Keyboard.current.wKey.isPressed) { if (Keyboard.current.wKey.isPressed) {
rb.AddForce(Vector3.forward * ballSpeed); _ball.AddForce(Vector3.forward * _ballSpeed);
} }
else if (Keyboard.current.sKey.isPressed) { else if (Keyboard.current.sKey.isPressed) {
rb.AddForce(Vector3.back * ballSpeed); _ball.AddForce(Vector3.back * _ballSpeed);
} }
else if (Keyboard.current.dKey.isPressed) { else if (Keyboard.current.dKey.isPressed) {
rb.AddForce(Vector3.right * ballSpeed); _ball.AddForce(Vector3.right * _ballSpeed);
} }
else if (Keyboard.current.aKey.isPressed) { else if (Keyboard.current.aKey.isPressed) {
rb.AddForce(Vector3.left * ballSpeed); _ball.AddForce(Vector3.left * _ballSpeed);
} }
if (Keyboard.current.spaceKey.isPressed && transform.position.y < 1) { if (Keyboard.current.spaceKey.isPressed && transform.position.y < 1) {
Debug.Log("KrossKross will make you..."); _ball.AddForce(Vector3.up * _jumpForce);
rb.AddForce(Vector3.up * jumpForce);
} }
else { else {
rb.AddForce(-rb.linearVelocity * brakeForce); _ball.AddForce(-_ball.linearVelocity * _brakeForce);
} }
} }
} }