using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI; using UnityEngine.Video; public class Game01 : MonoBehaviour { public GameObject rocket; // 火箭 public GameObject[] fires; // 成功发射的点火特效 public GameObject fog; // 失败时的冒烟特效 public GameObject panel; public VideoPlayer player; private GameObject left; private GameObject right; public GameObject next; private bool fired = false; // 是否点火成功 private float pretime = 3f; // 准备时间 private float timestamp = 0f; // 冷却时间 private float wait = 1f; // 等待时间 private int time = 1; // 倒计时 private int flag = 0; // 标记 private bool passed = false; private bool success = false; // Start is called before the first frame update void Start() { left = GameObject.Find("Left"); right = GameObject.Find("Right"); //next = GameObject.Find("Next"); } // Update is called once per frame void Update() { if (pretime > 0) { // 游戏正式开始前的准备时间 left.GetComponentInChildren().text = pretime.ToString("f0"); right.GetComponentInChildren().text = pretime.ToString("f0"); pretime -= Time.deltaTime; } else { GameLogic(); // 开始游戏主体逻辑 } // 火箭升空 if (fired) { rocket.transform.Translate(rocket.transform.up * 0.5f); if (!success) { Camera.main.transform.Translate(Camera.main.transform.up * 0.5f); } Invoke("Video", 10f); } } void GameLogic() { if (fired) return; if (timestamp < 1f + wait) { timestamp += Time.deltaTime; left.GetComponent().fillAmount = timestamp; right.GetComponent().fillAmount = timestamp; // waiting = timestamp >= 1f; if (timestamp >= 1f && flag == 0) { flag = Random.Range(-1, 2); if(flag == -1) { left.GetComponentInChildren().text = time.ToString("f0"); right.GetComponentInChildren().text = "X"; } else { left.GetComponentInChildren().text = "X"; right.GetComponentInChildren().text = time.ToString("f0"); } } if(flag == 0) { left.GetComponentInChildren().text = time.ToString("f0"); right.GetComponentInChildren().text = time.ToString("f0"); } } else { if (passed) { timestamp = 0f; flag = 0; } else { Failed(); } } } public void Video() { next.SetActive(true); success = true; player.Play(); } public void Select(int x) { if (flag == x) { passed = true; time -= 1; if(time < 0) { Success(); } } else { Failed(); } } void Success() { foreach (GameObject f in fires) { f.SetActive(true); } left.SetActive(false); right.SetActive(false); fired = true; } void Failed() { panel.SetActive(true); panel.GetComponentInChildren().text = "发射失败"; fog.SetActive(true); } public void Restart() { SceneManager.LoadScene(2); } public void Next() { SceneManager.LoadScene(3); } }