0
我有一個簡單的遊戲,玩家需要在30秒內收集4個遊戲物品。現在我已經創建了定時器,所以我需要讓遊戲知道如果所有遊戲對象都是在玩家獲勝的時限內收集的。玩家應該贏得所有物品的收集
這是我到目前爲止的代碼:
using UnityEngine;
using System.Collections;
public class GameState : MonoBehaviour
{
public static int count = 0;
public float seconds = 30;
public float minutes = 0;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
if (seconds <= 0)
{
seconds = 30;
if (minutes >= 1)
{
minutes -- ;
}
else
{
minutes = 0;
seconds = 0;
GameObject.Find("TimerText").guiText.text = minutes.ToString("f0") + ":0" + seconds.ToString("f0");
}
}
else
{
seconds -= Time.deltaTime;
}
if (Mathf.Round(seconds) <=9)
{
GameObject.Find("TimerText").guiText.text = minutes.ToString("f0") + ":0" + seconds.ToString("f0");
}
else
{
GameObject.Find("TimerText").guiText.text = minutes.ToString("f0") + ":" + seconds.ToString("f0");
}
if(count >= 1)
{
print("You Won!");
}
}
void OnTriggerEnter(Collider collide)
{
if (collide.transform.tag == "Cube")
{
count = count + 1;
Destroy (collide.gameObject);
}
}
}
注:立方體是遊戲對象需要被拾起的一個。
誰能幫我所有的冰塊是什麼時候? – GameOver