2014-01-11 43 views
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); 
     } 
    } 
} 

注:立方體是遊戲對象需要被拾起的一個。

+0

誰能幫我所有的冰塊是什麼時候? – GameOver

回答

0

你可以中斷遊戲或顯示勝利的菜單或者是你已經收集

void Update() 
{ 
    bool cubescollected = false; 
    if(cubescollected == 4) 
    { 
     ShowVictoryOrSomething(); 
     cubescollected = true 
    } 
    if(cubescollected == true) 
     return; 
... your timer code 
} 

好運和快樂編碼

相關問題