How to add text to a box ?
Hello everybody.
I have created a GUIBox, and I want it to display text when I ask for it. For example, when I press the button "Attack", a text appears in the box : "You attacked". The box will always be present.
I don't know if it's possible ?
Thanks for your answers and sorry for bad english, it's not my first language.
EDIT : this video help me a lot : https://www.youtube.com/watch?v=wlY5sRewfVQ
PLUS if it's possible, I want to conserve all the text in screen, not just 1 line, but for the moment I don't know how to do.
Answer by Pnvanol · Apr 08, 2016 at 10:28 AM
Gameobject ui text, to add the text Then you want to create a script in the text component Unityengine.Ui at the top of it Creat a public text textInsideBox
Drag the text element to the empty text box on the inspector. Then you can change textInsideBox from inside the script anytime you want
Thank you for your answer @Ponoveave. But I don't understand what you means by "gameobject ui text" ?
Ooooh O$$anonymous$$ !! Thank you !
So I create the UI > Text, and a script which contains : public Text textInsideBox;
How can I change the text in other script ??
Sorry, I'm a real noob here...
Ok to add lines you could try to do textInsideBox.text =textInsideBox.text+"anytextyouwanttoadd";
That works but all the text are stuck like this : "you attackyou attackyou attack", and if I use \n the first line just dissapear..
Well, like Ponoveave answer. Use the new UI. You can attach a script to detect your input (in your case the attack button) in the text object you create.
Answer by Dank_Mushies · Apr 23, 2016 at 03:08 AM
Try this simple example:
string customText;
onGUI()
{
GUI.Rect(new Rect(TextRect),""+customText);
if(GUI.Button(new Rect(buttonRect),"Attack Button")
{
customText = "Add your text here";
}
}
Your answer
Follow this Question
Related Questions
TextUI text changes size if resolution changes 1 Answer
Using Japanese in my game 1 Answer
TextMeshPro Set Alpha Color 0 Answers
How to draw text in a non-rectangular area 0 Answers
Stop Text object moving with player 2 Answers