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 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() {
_ball = GetComponent<Rigidbody>();
_controls = new PlayerControls();
@@ -46,10 +39,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) {
_moveInput = context.ReadValue<Vector2>();
}
void Update() {
CheckPlayerOut();
UpdateGUI();
}
private void FixedUpdate() {
Vector3 direction =
new Vector3(_moveInput.x, 0, _moveInput.y);
@@ -61,16 +67,6 @@ 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) {
other.gameObject.SetActive(false);
_pickupLeft--;
@@ -78,6 +74,11 @@ public class BallController : MonoBehaviour {
LevelDone();
}
void UpdateGUI() {
_pickupLeftText.text = "Left: " + _pickupLeft.ToString();
_timeSpentText.text = "Tid: " + Time.timeSinceLevelLoad.ToString("F1") + "s";
}
void LevelDone() {
_pickupLeftText.gameObject.SetActive(false);
_timeSpentText.gameObject.SetActive(false);