62 lines
1.6 KiB
C#
62 lines
1.6 KiB
C#
|
using System;
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using TMPro;
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
|
|||
|
public class GameOverManager : Singleton<GameOverManager>
|
|||
|
{
|
|||
|
public Image targetImage;
|
|||
|
public TMP_Text te;
|
|||
|
|
|||
|
// 游戏是否结束的标志
|
|||
|
private bool isGameOver = false;
|
|||
|
|
|||
|
private void Start()
|
|||
|
{
|
|||
|
targetImage = GetComponent<Image>();
|
|||
|
te = GetComponentInChildren<TMP_Text>();
|
|||
|
this.gameObject.SetActive(false);
|
|||
|
}
|
|||
|
|
|||
|
public void WinGame()
|
|||
|
{
|
|||
|
gameObject.SetActive(true);
|
|||
|
StartCoroutine(FadeCoroutine("您赢了!太阳之神永远地降临在此!"));
|
|||
|
}
|
|||
|
|
|||
|
public void LoseGame()
|
|||
|
{
|
|||
|
gameObject.SetActive(true);
|
|||
|
StartCoroutine(FadeCoroutine("您输了...\n黑暗无情的击破了你的城墙,太阳神将不再降临"));
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
private IEnumerator FadeCoroutine(string content)
|
|||
|
{
|
|||
|
// 获取当前颜色和目标颜色
|
|||
|
Color originalColor = targetImage.color;
|
|||
|
Color targetColor = new Color(originalColor.r, originalColor.g, originalColor.b, 1);
|
|||
|
|
|||
|
float timeElapsed = 0;
|
|||
|
|
|||
|
while (timeElapsed < 4)
|
|||
|
{
|
|||
|
// 计算过渡的比例
|
|||
|
float t = timeElapsed / 4;
|
|||
|
|
|||
|
// 插值更新颜色
|
|||
|
targetImage.color = Color.Lerp(originalColor, targetColor, t);
|
|||
|
|
|||
|
timeElapsed += Time.deltaTime;
|
|||
|
yield return null;
|
|||
|
}
|
|||
|
|
|||
|
// 确保最终颜色为目标颜色
|
|||
|
targetImage.color = targetColor;
|
|||
|
te.gameObject.SetActive(true);
|
|||
|
te.text = content;
|
|||
|
}
|
|||
|
}
|