gather-and-defend/Assets/Scripts/Drag&Drop/MaximumPopulationReachedCardAlert.cs

29 lines
791 B
C#

using GatherAndDefend.Events;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MaximumPopulationReachedCardAlert : MonoBehaviour
{
[SerializeField] private Animator _warningAnimator;
private void Start()
{
EventAggregator.Instance.GetEvent<PopulationChangedEvent>().Attach(HandlePopulationChangedEvent);
}
private void HandlePopulationChangedEvent(PopulationChangedEventArgs args)
{
if (args.Pop / args.MaxPop >= GlobalConfig.Instance.Current.populationWarningPercentage)
{
// Show warning
_warningAnimator.SetBool("isWarning", true);
}
else
{
// Hide warning
_warningAnimator.SetBool("isWarning", false);
}
}
}