- Home /
A big problem with Button, Please Help
Hello
I make this script to call an application when the plyer click the button. the script works fine that what i'm thinking first but the problem is when a click the button, the application start open in many time,
this is the script that i use
unction OnGUI () {
if (buttonOn ==true) {
if (GUI.Button (Rect (450, 500, 400, 120), "Question1")) {
windowOn = true;
}
if (windowOn == true) {
System.Diagnostics.Process.Start(Application.dataPath + "/TEKLILA.exe");
}
}
is there any solution to make my application open one time when i click the button. THanks for any help
Answer by Peter G · Aug 08, 2010 at 08:27 PM
Unless you turn buttonOn false after the user clicks the button once, then you will continue to open the application again and again. So he user clicks the button once then windowOn becomes true and every time OnGUI is called, you will open the application again.
I might do something like:
var appOpen = false;
function OnGUI () {
if (buttonOn) {
if (GUI.Button (Rect (450, 500, 400, 120), "Question1")) {
if(!appOpen) {
appOpen = true;
System.Diagnostics.Process.Start(Application.dataPath + "/TEKLILA.exe");
//MakeButtonAvailable(10); //Will let the user click the
//button again in 10 seconds.
}
}
}
}
/ function MakeButtonAvailable (seconds : int) { yield WaitForSeconds(seconds); appOpen = false; } /
This way, when the user hits the button, the app opens, then the button won't open up any more applications. You could easily add a yield in another function which I demonstrated in parenthesis to delay the user clicking the button again for x seconds.
Your answer
Follow this Question
Related Questions
Draw Camera On GUI? 1 Answer
Accessing local system ( File Browser ) 2 Answers
Help With Message System Script 1 Answer
Scoresystem wont function correctly 0 Answers
Linking event or custom callback for gui elements by using custom UI System 1 Answer