fgm24/Assets/Scripts/Misc/MainMenuTransitionAnimation.cs

51 lines
1.3 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.InputSystem;
public class MainMenuTransitionAnimation : MonoBehaviour
{
Animator animator;
private void Start()
{
animator = GetComponent<Animator>();
}
private void Update()
{
// if coming from game over dont imediatly detect input
if (Time.timeSinceLevelLoad < 1f)
return;
foreach (var controller in Gamepad.all)
{
if (controller.crossButton.IsPressed())
{
AnimationMainMenuStart();
}
}
}
public void AnimationMainMenuStart()
{
animator.SetTrigger("Start");
StartCoroutine(WaitBeforeSceneChange());
}
private IEnumerator WaitBeforeSceneChange()
{
var animInfo = animator.GetCurrentAnimatorStateInfo(0);
while (!(animInfo.normalizedTime >= 0.99f && animInfo.IsName("MenuTransition")))
{
animInfo = animator.GetCurrentAnimatorStateInfo(0);
yield return new WaitForSecondsRealtime(0.1f);
}
AudioManager.Instance.StopAllAudio();
SceneManager.LoadScene(1);
//SceneManager.sceneLoaded += () => AudioManager.stop
}
}