75 lines
1.9 KiB
C#
75 lines
1.9 KiB
C#
using System;
|
|
using System.Collections;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
using UnityEngine.UI;
|
|
|
|
public class MainMenuHandler : MonoBehaviour
|
|
{
|
|
[SerializeField] private Animator uiAnimator;
|
|
[SerializeField] private string openUIAction;
|
|
[SerializeField] private string closeUIAction;
|
|
[SerializeField] private string gameStartAction;
|
|
[SerializeField] private Transform uiMovingObject;
|
|
[SerializeField] private DialogueScript startingScript;
|
|
|
|
[Header("Scene Transition")]
|
|
[SerializeField] private Image screenFade;
|
|
[SerializeField] private float fadeSpeed;
|
|
|
|
private void Start()
|
|
{
|
|
//uiAnimator.SetTrigger(gameStartAction);
|
|
screenFade.gameObject.SetActive(false);
|
|
}
|
|
|
|
public void StartGame()
|
|
{
|
|
screenFade.gameObject.SetActive(true);
|
|
screenFade.color = Color.clear;
|
|
StartCoroutine(FadeScreen(2, startingScript));
|
|
GameManager.instance.gameOver = false;
|
|
GameManager.instance.canPause = true;
|
|
GameManager.instance.isEndless = false;
|
|
}
|
|
|
|
public void StartEndless()
|
|
{
|
|
screenFade.gameObject.SetActive(true);
|
|
screenFade.color = Color.clear;
|
|
StartCoroutine(FadeScreen(1, startingScript));
|
|
GameManager.instance.gameOver = false;
|
|
GameManager.instance.canPause = true;
|
|
GameManager.instance.isEndless = true;
|
|
}
|
|
|
|
public void QuitGame()
|
|
{
|
|
Application.Quit();
|
|
}
|
|
public void OpenUI(GameObject uiToOpen)
|
|
{
|
|
uiAnimator.SetTrigger(openUIAction);
|
|
uiToOpen.transform.SetParent(uiMovingObject);
|
|
uiToOpen.transform.position = uiMovingObject.position;
|
|
}
|
|
public void CloseUI(GameObject uiToClose)
|
|
{
|
|
uiAnimator.SetTrigger(closeUIAction);
|
|
}
|
|
|
|
private IEnumerator FadeScreen(int sceneToSwitchTo, DialogueScript scriptToShow)
|
|
{
|
|
float state = 0f;
|
|
while (state < 1f)
|
|
{
|
|
state += Time.deltaTime * fadeSpeed;
|
|
screenFade.color = Color.Lerp(Color.clear, Color.black, state);
|
|
if (state >= 1)
|
|
{
|
|
LevelSwitcher.instance.SwitchLevel(sceneToSwitchTo, scriptToShow);
|
|
}
|
|
yield return null;
|
|
}
|
|
}
|
|
}
|