44 lines
1016 B
C#
44 lines
1016 B
C#
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
using System.Collections;
|
|||
|
|
|||
|
public class FadeToBlack : MonoBehaviour
|
|||
|
{
|
|||
|
public float fadeDuration = 1.5f; // <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
|||
|
private Image blackImage;
|
|||
|
|
|||
|
void Start()
|
|||
|
{
|
|||
|
blackImage = GetComponent<Image>();
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
// <20>ⲿ<EFBFBD><E2B2BF><EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
public void StartFade()
|
|||
|
{
|
|||
|
StartCoroutine(FadeToBlackCoroutine());
|
|||
|
}
|
|||
|
|
|||
|
// <20>ⲿ<EFBFBD><E2B2BF><EFBFBD>ã<EFBFBD>ֱ<EFBFBD>ӱ<EFBFBD><D3B1><EFBFBD>
|
|||
|
public void InstantBlack()
|
|||
|
{
|
|||
|
blackImage.color = new Color(0, 0, 0, 1f); // <20><><EFBFBD><EFBFBD>Ϊȫ<CEAA><C8AB>
|
|||
|
}
|
|||
|
|
|||
|
// Э<>̣<EFBFBD><CCA3><EFBFBD><EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
private IEnumerator FadeToBlackCoroutine()
|
|||
|
{
|
|||
|
float elapsedTime = 0f;
|
|||
|
|
|||
|
while (elapsedTime < fadeDuration)
|
|||
|
{
|
|||
|
elapsedTime += Time.deltaTime;
|
|||
|
float alpha = Mathf.Clamp01(elapsedTime / fadeDuration); // <20><><EFBFBD><EFBFBD><EFBFBD><CDB8><EFBFBD><EFBFBD>
|
|||
|
blackImage.color = new Color(0, 0, 0, alpha);
|
|||
|
yield return null; // <20>ȴ<EFBFBD><C8B4><EFBFBD>һ֡
|
|||
|
}
|
|||
|
|
|||
|
// ȷ<><C8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD>
|
|||
|
blackImage.color = new Color(0, 0, 0, 0.6f);
|
|||
|
}
|
|||
|
}
|