miepzerino
2023-12-23 0e4e85ff5aced814ae95b923ee94574ebaa112bb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
 
public class LevelChanger : MonoBehaviour
{
    Animator animator;
 
    private int? levelToLoadIndex;
    private string levelToLoadName;
    private void Awake()
    {
        animator = GetComponent<Animator>();
    }
 
    // Update is called once per frame
    void Update()
    {
    }
 
    public void FadeToScene(int sceneIndex)
    {
        levelToLoadIndex = sceneIndex;
        animator.SetTrigger("FadeOut");
    }
    public void FadeToScene(string sceneName)
    {
        levelToLoadName = sceneName;
        animator.SetTrigger("FadeOut");
 
    }
 
    public void OnFadeComplete()
    {
        if (levelToLoadIndex.HasValue)
        {
            SceneManager.LoadScene(levelToLoadIndex.Value);
            levelToLoadIndex = null;
        } 
        else if(levelToLoadName != null)
        {
            SceneManager.LoadScene(levelToLoadName);
            levelToLoadName = null;
        }
    }
}