mycj_demo/mycj/Assets/Script/Penal.cs
2024-12-02 09:37:47 +08:00

91 lines
2.1 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class Penal : MonoBehaviour
{
public static Penal instance;
public GameObject Panel;
public Text Paneltext;
public Button againBTNNext;
public Button PanelBTNNext;
public Button PanelBTNClose;
public GameObject djs;
// Start is called before the first frame update
private void Awake()
{
instance = this;
}
void Start()
{
Panel.SetActive(false);
againBTNNext.onClick.AddListener(()=> {
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
});
PanelBTNNext.onClick.AddListener(()=> { });
PanelBTNClose.onClick.AddListener(()=> {
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
#else
Application.Quit();
#endif
});
//Daojishi(5f);
}
// Update is called once per frame
void Update()
{
}
public void GameVictory()
{
Panel.SetActive(true);
Panel.GetComponent<Image>().color = Color.blue;
Paneltext.text = "Victory";
Paneltext.color = Color.yellow;
againBTNNext.gameObject.SetActive(false);
PanelBTNNext.gameObject.SetActive(true);
PanelBTNClose.gameObject.SetActive(true);
}
public void GameOver()
{
Panel.SetActive(true);
Panel.GetComponent<Image>().color = Color.red;
Paneltext.text = "GameOver";
Paneltext.color = Color.black;
againBTNNext.gameObject.SetActive(true);
PanelBTNNext.gameObject.SetActive(false);
PanelBTNClose.gameObject.SetActive(true);
}
public void Daojishi(float number)
{
StartCoroutine(daojishi(number));
}
IEnumerator daojishi(float number)
{
float temp = number;
while (temp > 0.01f)
{
djs.GetComponent<Text>().text = temp.ToString();
temp -= 1;
yield return new WaitForSeconds(1);
}
djs.SetActive(false);
}
}