🌟期末專案_嗨!地鼠
🌠程式碼撰寫 — 第三關及每關過關分數判斷
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class HardControl : MonoBehaviour {
public static float gametimer;
float roundTimer,score;
int max;
bool gameOver = false, round = false;
public GameObject s3Mouse;
public List<ControlMouse3> mouse = new List<ControlMouse3>();
public List<Transform> hole = new List<Transform>();
public static float gametimer;
float roundTimer,score;
int max;
bool gameOver = false, round = false;
public GameObject s3Mouse;
public List<ControlMouse3> mouse = new List<ControlMouse3>();
public List<Transform> hole = new List<Transform>();
void Start()
{
gametimer = 30f;
roundTimer = 0f;
{
gametimer = 30f;
roundTimer = 0f;
gameOver = false;
score = 0;
}
void Update()
{
if (!gameOver)
{
if (gametimer <= 0) gameOver = true;
{
if (!gameOver)
{
if (gametimer <= 0) gameOver = true;
gametimer -= Time.deltaTime;
roundTimer -= Time.deltaTime;
//Debug.Log(gametimer);
roundTimer -= Time.deltaTime;
//Debug.Log(gametimer);
if (!gameOver && roundTimer <= 0.2f)
{
round = true;
roundTimer = 4f;
}
{
round = true;
roundTimer = 4f;
}
if (round)
{
max = Random.Range(5, 10);
while (max > 0)
{
max -= 1;
spawnS3Mouse();
}
round = false;
}
}
{
max = Random.Range(5, 10);
while (max > 0)
{
max -= 1;
spawnS3Mouse();
}
round = false;
}
}
if (gameOver)
{
if (score >= 300) SceneManager.LoadScene("Finish");
else
{
SceneManager.LoadScene("Easy");
}
}
}
{
if (score >= 300) SceneManager.LoadScene("Finish");
else
{
SceneManager.LoadScene("Easy");
}
}
}
void spawnS3Mouse() //產生第三關的地鼠
{
int index = Random.Range(0, 16);
while (mouse[index] != null) index = Random.Range(0, 16);
Destroy(s3One, 3f);
}
}
{
int index = Random.Range(0, 16);
while (mouse[index] != null) index = Random.Range(0, 16);
GameObject s3One = Instantiate(s3Mouse, new Vector3(hole[index].position.x,
hole[index].position.y - 15f, hole[index].position.z), hole[index].transform.rotation);
mouse[index] = s3One.GetComponent<ControlMouse3>();Destroy(s3One, 3f);
}
}
執行結果如下
沒有留言:
張貼留言