I am trying to perform a transition animation when a button is pressed. I am trying to use an if statement to check if the button is pressed to therefore then proceed with the transition.
This is the code for the transition which currently just loads the next scene when the mouse is clicked.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class SceneLoader : MonoBehaviour
{
public Animator transition;
public float transitionTime = 1f;
// Update is called once per frame
void Update()
{
if(Input.GetMouseButtonDown(0))
{
LoadNextScene();
}
}
public void LoadNextScene()
{
StartCoroutine(LoadScene(SceneManager.GetActiveScene().buildIndex + 1));
}
IEnumerator LoadScene(int sceneIndex )
{
//Play animation
transition.SetTrigger("Start");
//Wait
yield return new WaitForSeconds(transitionTime);
//Load scene
SceneManager.LoadScene(sceneIndex);
}
}
This is the code for the main menu that contains functions for the Play Button and Quit Button
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class MainMenu : MonoBehaviour
{
public void PlayGame()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
}
public void QuitGame()
{
Debug.Log("QUIT!");
Application.Quit();
}
}
Effectively I am trying to press the play button and load the next scene and also play the transition.
Any help would be appreciated.