2016-11-09 52 views
-2

我的問題是:我玩的遊戲,我想如果你輸了,立即在屏幕的頂部必須出現一個帶有「Record:X」的文本,我不想改變場景或什麼的,沒有,我只想把在屏幕頂部的文本在同一場景中,像堆棧如何在場景中顯示文本?

是可能的?

我的代碼例如是一個2碰撞的對象,當他們碰撞時,我想把這個文本放在頂部。

public class Colision : MonoBehaviour { 

    public Text points; 
    int contador=0; 
    int Veces_Pequeño=0; 

    void OnCollisionEnter(Collision col){ 
     if (col.gameObject.name == "Cube") { 
      col.gameObject.SetActive (false); 
     } 

     if (col.gameObject.name == "Cube1") { 
      col.gameObject.SetActive (false); 
     } 
    } 
} 
+0

我要像在STACK!堆疊以文字開始,正下方出現一個帶按鈕和場景的遊戲,如果輸了,文本「RECORD」立即出現在頂部。怎麼樣?? –

+0

語言是C# –

+0

團結:)對不起! –

回答

3

我無法理解你的要求,但如果它是那樣簡單,因爲我覺得是,確保分被禁止啓動遊戲時,並添加該代碼時,你想點被顯示。

//Set the text to what ever you would like. 
points.text = "Record: " + contador; 
//Enable the gameobject for it to be seen. 
points.gameObject.SetActive(true); 
+0

是的,但我想用我的自定義字體「RECORD」 –

+0

好吧,那麼我建議在水平佈局組中使用兩個文本,其中第一個文本帶有您的自定義字體的文本「RECORD」,第二個是連接到變量點。 – Alox

+0

但我怎麼能出現這個文本?佈局是在哪個場景裏面? –

0

好吧,你可以改變的Texttextenabled性能。

我假設你有文本組件和畫布遊戲物體...

public class Colision : MonoBehaviour { 

    public Text points; 
    int contador = 0; 
    int Veces_Pequeño = 0; 
    public string beforeText = "record: "; //just added this so it is easy to change in unity editor 

    void Start(){ 
     points.enabled = false; 
    } 

    void OnCollisionEnter(Collision col){ 
     if (col.gameObject.name == "Cube") { 
      col.gameObject.SetActive (false); 
      points.text = beforeText + contador.toString(); 
      points.enabled = true; 
     } 

     if (col.gameObject.name == "Cube1") { 
      col.gameObject.SetActive (false); 

      points.text = beforeText + contador.toString(); 
      points.enabled = true; 
     } 
    } 
} 

這應該有很大的幫助: https://docs.unity3d.com/Manual/script-Text.html

相關問題