gather-and-defend/Assets/Scripts/VictoryDefeat.cs

46 lines
1.4 KiB
C#

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 void Start()
{
_isShowingVictoryOrDefeat = false;
}
void Update()
{
if (_isShowingVictoryOrDefeat) return;
List<LevelObject> opponentsList = LevelManager.Instance.GetAll<LevelObject>(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;
//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 :(
}
}
}
}