- Home /
Help much appreciated with buttons and text fields please
Hi, This is the 1st time I have asked a question so I apologise now if its not done properly.
I am very new to Unity and I'm struggling with creating some buttons on my interface.
I have the buttons, they work when pressed - the text appears where it should, but then when the next button is clicked it just pastes the new text over the top of the other. It does this for all 6 buttons. My question is how do I get the text to disappear when another button is pressed? I don't mind the text being there until another button is clicked, just don't want it pasting it on top of each other.
I also apologise if my script is not very good, I know there must be a shorter way of writing what I have already.
Thanks in advance.
var submitPressed = false;
var msgtxt = "This info will be about the Colosseum from 60-72AD";
var submitPressed2 = false;
var msgtxt2 = "This info will be about the Colosseum from 72-90AD";
var submitPressed3 = false;
var msgtxt3 = "This info will be about the games at the Colosseum";
var submitPressed4 = false;
var msgtxt4 = "This info will be about the gladiators";
var submitPressed5 = false;
var msgtxt5 = "This info will be about the construction of the Colosseum";
var submitPressed6 = false;
var msgtxt6 = "This info will be about the Emperors";
function OnGUI() {
GUI.skin = MenuSkin;
GUI.BeginGroup(new Rect(Screen.width/2-600,Screen.height/2-350,700,700));
GUI.Box(Rect(0,0,300,700),"The Roman Colosseum");
GUI.Button(Rect(10,30,130,50),"Fly Through One");
GUI.Button(Rect(160,30,130,50),"Fly Through Two");
if( GUI.Button(Rect(10,90,130,50),"60AD - 72AD")){
submitPressed = true;
}
if( submitPressed ) {
GUI.Box(Rect(10,270,280,420),msgtxt );
}
if( GUI.Button(Rect(160,90,130,50),"72AD - 90AD")){
submitPressed2 = true;
}
if( submitPressed2 ) {
GUI.Box(Rect(10,270,280,420),msgtxt2 );
}
if( GUI.Button(Rect(10,150,130,50),"The Games")){
submitPressed3 = true;
}
if( submitPressed3 ) {
GUI.Box(Rect(10,270,280,420),msgtxt3 );
}
if( GUI.Button(Rect(160,150,130,50),"Gladiators")){
submitPressed4 = true;
}
if( submitPressed4 ) {
GUI.Box(Rect(10,270,280,420),msgtxt4 );
}
if( GUI.Button(Rect(160,210,130,50),"Emperors")){
submitPressed5 = true;
}
if( submitPressed5 ) {
GUI.Box(Rect(10,270,280,420),msgtxt5 );
}
if( GUI.Button(Rect(10,210,130,50),"Construction")){
submitPressed6 = true;
}
if( submitPressed6 ) {
GUI.Box(Rect(10,270,280,420),msgtxt6 );
}
GUI.EndGroup ();
}
Your answer
Follow this Question
Related Questions
How do I delay the appearance of these buttons? 3 Answers
OnGUI elements in editor scene view 1 Answer
UI Buttons dont react on click 4 Answers
How to make this text box disappear after a set amount of time? 1 Answer
text box and button won't display 2 Answers