Satte rätt ordning på funktionerna

This commit is contained in:
2026-09-16 20:13:50 +02:00
parent de902fa0a2
commit 98fdddb686

View File

@@ -19,13 +19,6 @@ public class BallController : MonoBehaviour {
private Vector2 _moveInput; private Vector2 _moveInput;
private PlayerControls _controls; private PlayerControls _controls;
void Start() {
_ballSpeed = 5f;
_brakeForce = 0.3f;
_jumpForce = 300f;
_pickupLeft = GameObject.FindGameObjectsWithTag("PickUp").Length;
transform.position = new Vector3(0, 0.5f, 0);
}
private void Awake() { private void Awake() {
_ball = GetComponent<Rigidbody>(); _ball = GetComponent<Rigidbody>();
_controls = new PlayerControls(); _controls = new PlayerControls();
@@ -45,10 +38,23 @@ public class BallController : MonoBehaviour {
} }
}; };
} }
void Start() {
_ballSpeed = 5f;
_brakeForce = 0.3f;
_jumpForce = 300f;
_pickupLeft = GameObject.FindGameObjectsWithTag("PickUp").Length;
transform.position = new Vector3(0, 0.5f, 0);
}
public void OnMove(InputAction.CallbackContext context) { public void OnMove(InputAction.CallbackContext context) {
_moveInput = context.ReadValue<Vector2>(); _moveInput = context.ReadValue<Vector2>();
} }
void Update() {
CheckPlayerOut();
UpdateGUI();
}
private void FixedUpdate() { private void FixedUpdate() {
Vector3 direction = Vector3 direction =
@@ -61,22 +67,17 @@ public class BallController : MonoBehaviour {
} }
} }
void Update() {
CheckPlayerOut();
UpdateGUI();
}
void UpdateGUI() {
_pickupLeftText.text = "Left: " + _pickupLeft.ToString();
_timeSpentText.text = "Tid: " + Time.timeSinceLevelLoad.ToString("F1") + "s";
}
void OnTriggerEnter(Collider other) { void OnTriggerEnter(Collider other) {
other.gameObject.SetActive(false); other.gameObject.SetActive(false);
_pickupLeft--; _pickupLeft--;
if (_pickupLeft == 0) if (_pickupLeft == 0)
LevelDone(); LevelDone();
} }
void UpdateGUI() {
_pickupLeftText.text = "Left: " + _pickupLeft.ToString();
_timeSpentText.text = "Tid: " + Time.timeSinceLevelLoad.ToString("F1") + "s";
}
void LevelDone() { void LevelDone() {
_pickupLeftText.gameObject.SetActive(false); _pickupLeftText.gameObject.SetActive(false);