diff --git a/Assets/Code/Gameplay/AICarController.cs b/Assets/Code/Gameplay/AICarController.cs index 21bf930..d3e56ee 100644 --- a/Assets/Code/Gameplay/AICarController.cs +++ b/Assets/Code/Gameplay/AICarController.cs @@ -4,12 +4,14 @@ namespace Code.Gameplay { public class AICarController : MonoBehaviour { - [SerializeField] private float speed = 15f; + [SerializeField] public float speed = 15f; [SerializeField] private float stoppingDistance = 2f; [SerializeField] private float turnSpeed = 3f; private Vector3[] _waypoints; private int _currentWaypointIndex; + + private bool _isStopped; public void SetRoute(Vector3[] waypoints) { @@ -19,7 +21,14 @@ namespace Code.Gameplay private void Update() { - if (_waypoints == null || _waypoints.Length == 0) return; + if (_waypoints == null || _waypoints.Length == 0 || _isStopped) return; + + if (_currentWaypointIndex >= _waypoints.Length - 1) + { + var raceManager = FindFirstObjectByType(); + raceManager?.OnLoose(); + _isStopped = true; + } var target = _waypoints[_currentWaypointIndex]; var direction = target - transform.position; diff --git a/Assets/Code/Gameplay/FinishTrigger.cs b/Assets/Code/Gameplay/FinishTrigger.cs index b9f2576..0f09781 100644 --- a/Assets/Code/Gameplay/FinishTrigger.cs +++ b/Assets/Code/Gameplay/FinishTrigger.cs @@ -11,6 +11,11 @@ namespace Code.Gameplay var raceManager = FindFirstObjectByType(); raceManager?.OnFinish(); } + else if (other.CompareTag("AI")) + { + var raceManager = FindFirstObjectByType(); + raceManager?.OnLoose(); + } } } } \ No newline at end of file diff --git a/Assets/Code/Gameplay/RaceManager.cs b/Assets/Code/Gameplay/RaceManager.cs index 24c1c72..28c8a47 100644 --- a/Assets/Code/Gameplay/RaceManager.cs +++ b/Assets/Code/Gameplay/RaceManager.cs @@ -1,6 +1,7 @@ using Code.DI; using Code.Input; using Code.Records; +using Code.UI; using DG.Tweening; using TMPro; using UnityEngine; @@ -11,14 +12,15 @@ namespace Code.Gameplay { public class RaceManager : MonoBehaviour { - [Header("UI")] [SerializeField] private TMP_Text countdownText; [SerializeField] private TMP_Text timerText; [SerializeField] private GameObject resultsWrapper; + [SerializeField] private GameObject youLoseWrapper; - [Header("Settings")] [SerializeField] private float countdownDuration = 3f; [SerializeField] private float startDelayAfterGo = 0.5f; + + [SerializeField] private AICarController aiCar; private float _startTime; private float _elapsedTime; @@ -28,6 +30,9 @@ namespace Code.Gameplay private TMP_InputField _nameField; private Button _restartButton; private Button _toMenuButton; + + private Button _restartButtonLose; + private Button _toMenuButtonLose; private void Awake() { @@ -36,9 +41,12 @@ namespace Code.Gameplay _nameField = resultsWrapper.transform.Find("EnterNameField")?.GetComponent(); _restartButton = resultsWrapper.transform.Find("RestartButton")?.GetComponent