using System.Collections; using System.Collections.Generic; using UnityEngine; public class VictoryDefeat : MonoBehaviour { private bool _wavesEnd = false; private bool _isShowingVictoryOrDefeat = false; [SerializeField] private Animator _victoryAnimator; [SerializeField] private Animator _defeatAnimator; public const float positionLoseLimit = -10.0f; private WorldMapSave _wms; private void Start() { _wms = new WorldMapSave(); _isShowingVictoryOrDefeat = false; } void Update() { if (_isShowingVictoryOrDefeat) return; List opponentsList = LevelManager.Instance.GetAll(x => x is Opponent); //I believe that we win if the waves are finished and there are no more monsters (to be modified in the case that's not it) if(_wavesEnd && opponentsList.Count == 0) { _victoryAnimator.Play("ShowVictoryOrDefeat"); _isShowingVictoryOrDefeat = true; _wms.UnlockNextLevel(); //win ! } //I estimate that we lose if one of the enemies arrives behind our line of defense (to be modified in the case it's not that) foreach (Opponent opponent in opponentsList) { if (opponent == null) return; if (opponent.transform.position.x < positionLoseLimit) { _defeatAnimator.Play("ShowVictoryOrDefeat"); _isShowingVictoryOrDefeat = true; //lose :( } } } }