一个类
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Globe
{
public static string Name;
}
//挂载脚本
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
//淡入淡出
public class SceneFadeInOut : MonoBehaviour
{
public float fadeSpeed = 1.5f;
public bool sceneStarting = true;
public static bool sceneEnding = false;
private RawImage rawImage;
void Awake()
{
rawImage = GetComponent<RawImage>();
}
void Start()
{
}
void Update()
{
if (sceneStarting)
{
//StartScene();
}
if (sceneEnding)
{
EndScene();
}
}
private void FadeToClear()
{
rawImage.color = Color.Lerp(rawImage.color, Color.clear, fadeSpeed * Time.deltaTime);
}
private void FadeToBlack()
{
rawImage.color = Color.Lerp(rawImage.color, Color.black, fadeSpeed * Time.deltaTime);
}
void StartScene()
{
FadeToClear();
if (rawImage.color.a < 0.05f)
{
rawImage.color = Color.clear;
rawImage.enabled = false;
sceneStarting = false;
}
}
void EndScene()
{
rawImage.enabled = true;
FadeToBlack();
if (rawImage.color.a > 0.95f)
{
sceneEnding = false;
SceneManager.LoadScene(Globe.Name);
}
}
void OnDestroy()
{
}
}
使用
//下一关
private void Next()
{
Globe.Name = "LV2";
SceneFadeInOut.sceneEnding = true;
}