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.

117 lines
2.6 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using UnityEngine.Video;
public class Game02 : MonoBehaviour
{
public GameObject rocket; // 火箭
public GameObject[] fires; // 成功发射的点火特效
public GameObject fog; // 失败时的冒烟特效
public GameObject panel;
public VideoPlayer player;
public GameObject StatusBar;
public GameObject button;
public GameObject next;
private bool fired = false; // 是否点火成功
public float pretime = 3f; // 准备时间
private float timestamp = 0f; // 冷却时间
public float wait = 1f; // 等待时间
public float time = 10f; // 倒计时
public int flag = 0; // 标记
private bool passed = false;
private bool success = false;
public int count = 0;
public int maxCount = 100;
// Start is called before the first frame update
void Start()
{
timestamp = time;
StatusBar.GetComponent<Slider>().minValue = count;
StatusBar.GetComponent<Slider>().maxValue = maxCount;
}
// Update is called once per frame
void Update()
{
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;
timestamp -= Time.deltaTime;
button.GetComponentInChildren<Text>().text = timestamp.ToString("0");
if (timestamp < 0f)
{
if (count > maxCount)
{
Success();
}
else
{
Failed();
}
}
}
public void Video()
{
next.SetActive(true);
success = true;
player.Play();
}
public void Add()
{
count++;
StatusBar.GetComponent<Slider>().value = count;
StatusBar.GetComponentInChildren<Text>().text = count.ToString();
}
void Success()
{
foreach (GameObject f in fires)
{
f.SetActive(true);
}
button.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);
}
}