You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

156 lines
3.9 KiB

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>().text = pretime.ToString("f0");
right.GetComponentInChildren<Text>().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<Image>().fillAmount = timestamp;
right.GetComponent<Image>().fillAmount = timestamp;
// waiting = timestamp >= 1f;
if (timestamp >= 1f && flag == 0)
{
flag = Random.Range(-1, 2);
if(flag == -1)
{
left.GetComponentInChildren<Text>().text = time.ToString("f0");
right.GetComponentInChildren<Text>().text = "X";
}
else
{
left.GetComponentInChildren<Text>().text = "X";
right.GetComponentInChildren<Text>().text = time.ToString("f0");
}
}
if(flag == 0)
{
left.GetComponentInChildren<Text>().text = time.ToString("f0");
right.GetComponentInChildren<Text>().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>().text = "发射失败";
fog.SetActive(true);
}
public void Restart() {
SceneManager.LoadScene(2);
}
public void Next()
{
SceneManager.LoadScene(3);
}
}