Чтобы ошибки не сыпало при старте на gameplay сцене А то OnDestroy отрабатывают и спамят консоль
39 lines
938 B
C#
39 lines
938 B
C#
using UnityEngine;
|
|
using static EndGameConditionChecker;
|
|
|
|
public class EndgameAnimationsStarter : MonoBehaviour
|
|
{
|
|
[SerializeField] private GameObject Win;
|
|
[SerializeField] private GameObject Loose;
|
|
[SerializeField] private GameObject Completed;
|
|
|
|
private bool initialized = false;
|
|
public void Init()
|
|
{
|
|
Win.SetActive(false);
|
|
Loose.SetActive(false);
|
|
Completed.SetActive(false);
|
|
|
|
G.Terminator.OnTerminate += ShowAnim;
|
|
initialized = true;
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
if (!initialized) return;
|
|
G.Terminator.OnTerminate -= ShowAnim;
|
|
}
|
|
|
|
private void ShowAnim(EndgameReason reason)
|
|
{
|
|
var animGO = reason switch
|
|
{
|
|
EndgameReason.Timeout => Win,
|
|
EndgameReason.NoAmmo => Completed,
|
|
EndgameReason.Death => Loose,
|
|
_ => Completed
|
|
};
|
|
animGO.SetActive(true);
|
|
}
|
|
}
|