2016-11-09 53 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

相关问题