如何保留旧行文字? [英] How to keep the old line text?

查看:109
本文介绍了如何保留旧行文字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图弄清楚这一点,但没有成功。我想要做的是保留旧文本,同时脚本在旧文本下添加新文本。



 public GameObject Text_Object; < br /> 
private Text textComponent;< br />
void Start(){< br />
//获取canvas组件中的文本UI对象< br />
textComponent = Text_Object.GetComponent< Text>();< br />
textComponent.text =Hello;< br />
Text2();< br />
}< br />
< br />
void Text2(){< br />
textComponent.text =Hey;< br />
}





基本上你可以看到第一个文本被替换为第二个文本。我正在尝试做的是保留旧文本,而如果我按T它会在旧文本下面打印新文本,并在它们点击D时添加命令,它会清除文本新旧文本。



我尝试了什么:



我试过研究它但却什么都没发现

解决方案

 textComponent.text = textComponent.text +  嘿嘿; 


Richard为您提供了解决方案,但您需要更深入地学习JS。



http://www.w3schools.com/js/default.asp [ ^ ]

W3Schools在线网络教程 [ ^ ]

I have been trying to figure out this but with no success . What I am trying to do is to keep the old text while the script adds the new text below the old text.

public GameObject Text_Object;<br />
         private Text textComponent;<br />
 void Start () {<br />
         //gets the text UI Object in canvas component<br />
         textComponent = Text_Object.GetComponent<Text>();<br />
                 textComponent.text = "Hello";<br />
                 Text2();<br />
     }<br />
<br />
 void Text2(){<br />
 textComponent.text = "Hey";<br />
 }



Basically as you can see the first text gets replace with the second text. What I'm trying to do keep the old text while if I press T it prints the new text below the old text and also add a command when they hit D it clears the text new and old text.

What I have tried:

I have tried researching it but found nothing

解决方案

textComponent.text = textComponent.text + "Hey";


Richard gave you a solution, but you need to learn JS much deeper.

http://www.w3schools.com/js/default.asp[^]
W3Schools Online Web Tutorials[^]


这篇关于如何保留旧行文字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆