fgm24/Assets/Scripts/Misc/MainMenuTransitionAnimation.cs

51 lines
1.3 KiB
C#
Raw Normal View History

2024-02-03 00:34:11 +01:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
2024-02-03 18:02:20 +01:00
using UnityEngine.SceneManagement;
2024-02-04 11:37:29 +01:00
using UnityEngine.InputSystem;
2024-02-03 00:34:11 +01:00
public class MainMenuTransitionAnimation : MonoBehaviour
{
Animator animator;
private void Start()
{
animator = GetComponent<Animator>();
}
2024-02-04 11:37:29 +01:00
private void Update()
{
2024-02-06 14:32:09 +01:00
// if coming from game over dont imediatly detect input
if (Time.timeSinceLevelLoad < 1f)
return;
2024-02-04 11:37:29 +01:00
foreach (var controller in Gamepad.all)
{
if (controller.crossButton.IsPressed())
{
AnimationMainMenuStart();
}
}
}
2024-02-03 00:34:11 +01:00
public void AnimationMainMenuStart()
{
animator.SetTrigger("Start");
2024-02-03 18:02:20 +01:00
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);
}
2024-02-04 16:32:14 +01:00
AudioManager.Instance.StopAllAudio();
2024-02-03 18:02:20 +01:00
SceneManager.LoadScene(1);
2024-02-04 08:40:08 +01:00
//SceneManager.sceneLoaded += () => AudioManager.stop
2024-02-03 00:34:11 +01:00
}
}