- Home /
GUI create 2 buttons after activated when user clicks the mouse
my problem is that I want to make 2 GUI buttons apear when the player clicks on a button one saying "New Game" and the other "Continue" can some one pls help me
the code I used is :
var levelToLoad : String;
var soundhover : AudioClip;
var beep : AudioClip;
var QuitButton : boolean = false;
function OnMouseEnter(){
audio.PlayOneShot(soundhover);
}
function OnMouseUp(){
audio.PlayOneShot(beep);
yield new WaitForSeconds(0.35);
if(QuitButton){
Application.Quit();
}
else{
function OnGUI(){
// Make a group on the center of the screen
GUI.BeginGroup (Rect (Screen.width / 2 - 50, Screen.height / 2 - 50, 100, 100));
// All rectangles are now adjusted to the group. (0,0) is the topleft corner of the group.
// make a box for group
GUI.Box (Rect (0,0,100,100), "Game Options");
GUI.Button (Rect (10,40,80,30), "New Game");
GUI.Button (Rect (10,50,80,30), "Continue");
// End the group we started above
GUI.EndGroup ();
}
}
@script RequireComponent(AudioSource)
Answer by worldofcars · Apr 07, 2012 at 01:35 AM
var shownewgame : boolean = false;
var showcontinue : boolean = false;
function Update(){ }
function OnGUI(){
if(GUI.Button(Rect(0,0,200,30),"Show the other 2 buttons")){
shownewgame = true;
showcontinue = true;
}
if(shownewgame == true){
if(GUI.Button(Rect(0,40,200,30),"New Game")){
//Code for new game button
}
}
if(showcontinue == true){
if(GUI.Button(Rect(0,80,200,30),"Continue")){
//Code for continue button
}
}
}
//This must work;) If you have any questions, let me know;)
Answer by poxqo · Apr 06, 2012 at 11:58 PM
You can make something like this:
function OnGUI(){
if GUI.Button (Rect (10,0,80,30), "Button that triggers two more btns");
{
if GUI.Button (Rect (10,40,80,30), "New Game");
{
// code for New Game Button
}
if GUI.Button (Rect (10,80,80,30), "Continue");
{
// code for Continue button
}
}
}
This invokes a button that calls two more new buttons while pressed. PLEASE adjust the Rect coordinates in THIS code so they fit your own GUI design. Hope this helps you –if not, just let know :) Greetings from México.
Answer by darkcookie · Apr 07, 2012 at 12:23 AM
I got all these errrors
The script is full of mistakes. I'll write you a new one
Your answer
Follow this Question
Related Questions
How to continue a dialog (GUI.Label) with answering Buttons? 1 Answer
Make a Button out of a Textured Plane 2 Answers
[C#] Xbox D'Pad to cycle through GUI.Buttons? 2 Answers
Button Input 1 Answer
GUI.Button background image 0 Answers