Scripting 收集所有物品时,玩家应获胜
我有一个简单的游戏,玩家需要在30秒内收集4个游戏对象。现在我已经创建了计时器,所以我需要让游戏知道,如果所有游戏对象都在时间限制下收集,那么玩家将获胜 这是我目前的代码:Scripting 收集所有物品时,玩家应获胜,scripting,unity3d,Scripting,Unity3d,我有一个简单的游戏,玩家需要在30秒内收集4个游戏对象。现在我已经创建了计时器,所以我需要让游戏知道,如果所有游戏对象都在时间限制下收集,那么玩家将获胜 这是我目前的代码: using UnityEngine; using System.Collections; public class GameState : MonoBehaviour { public static int count = 0; public float seconds = 30; public
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);
}
}
}
注意:立方体是需要拾取的游戏对象之一。收集所有立方体后,您可以中断游戏或显示胜利菜单或其他内容
void Update ()
{
bool cubescollected = false;
if(cubescollected == 4)
{
ShowVictoryOrSomething();
cubescollected = true
}
if(cubescollected == true)
return;
... your timer code
}
祝你好运,快乐