i want display GUIBOX if certain condition meets…u can see in my code if(rand4 == rand3)
i am displaying guibox and then i am calling start() function…
but whenever i run my program in unity and above condition meets then it directly calls start() function…
but i want first to display guibox or label then adding scores and then to call start()…plz look at my code…
#pragma strict
var rand1:int;
var rand2:int;
var rand3:int;
var rand4:int;
var ran:int;
var currTry:int = 0; //Increment when click on button
var maxTry:int = 20;
var score : int = 0;
var guiScore : GUIText;
function Awake()
{
}
function Start()
{
ran = Random.Range(0,3);
rand1 = Random.Range(0, 20);//Random number1
rand2= Random.Range(0,20);//Random number2
rand3= Random.Range(0,40);//Random number3
rand4 = rand1 + rand2; //Internally calculation
Debug.Log(rand4);
guiScore.text = "Score: 0";
}
function Update () {
}
function Score()
{
if(GUI.Button(Rect(10,70,50,30),"right"))//GUI button for right
{
currTry++; //Increment Here
if(rand4 == rand3)
{
GUI.Box(Rect(120,70,50,30),"ITS WORKING");
score += 10;
guiScore.text = "Score: " + score;
Start();
//Awake();
//first();
}
else
{
//GUI.Box(Rect(120,70,50,30),"ITS NOT WORKING");
Destroy(this.gameObject);
}
}//for
if(GUI.Button(Rect(90,70,50,30),"wrong"))//GUI button for wrong
{
currTry++; //Increment Here Again
if(rand4 != rand3)
{
score += 10;
guiScore.text = "Score: " + score;
GUI.Box(Rect(120,70,50,30),"ITS WORKING");
Start();
// Awake(); //first();
}
else
{
GUI.Box(Rect(120,70,50,30),"ITS NOT WORKING");
Destroy(this.gameObject);
}
}
}
function OnGUI()
{
if(currTry < maxTry) //check if we
{
//GUI.Button(Rect(150,70,50,30),"##");
//GUI.Button(Rect(200,70,50,30),"**");
GUI.Box (Rect (30,5,25,30), rand1.ToString());//first random number
GUI.Box (Rect (90,5,25,30), rand2.ToString());//second random number
GUI.Box (Rect (150,5,25,30), rand3.ToString());//third random number
//GUI.Box (Rect (60,5,25,30),"+");//for +symbol
GUI.Box (Rect (60,5,25,30),GetRandomOperator());
GUI.Box (Rect (120,5,25,30),"=");//for equals to
Score();
}
else
{
Debug.Log("-----------------------------------MAX TRY COMPLETED-------------------------------");
///Do Something else after 20 Try Done
}
}
function GetRandomOperator()
{
//var ran:int;
//ran = Random.Range(0,4);
switch(ran)
{
case 0:
return "+";
case 1:
return "-";
case 2:
return "*";
}
}
/*
var rand1:int;
var rand2:int;
var rand3:int;
var rand4:int;
function Start()
{
rand1 = Random.Range(0, 10);//Random number1
rand2= Random.Range(0,10);//Random number2
rand3= Random.Range(2,19);//Random number3
rand4 = rand1 + rand2; //Internally calculation
Debug.Log(rand4);
}
function OnGUI()
{
GUI.Box (Rect (30,5,25,30), rand1.ToString());//first random number
GUI.Box (Rect (90,5,25,30), rand2.ToString());//second random number
GUI.Box (Rect (150,5,25,30), rand3.ToString());//third random number
GUI.Box (Rect (60,5,25,30),"+");//for +symbol
GUI.Box (Rect (120,5,25,30),"=");//for equals to
if(GUI.Button(Rect(10,70,50,30),"right"))//GUI button for right
{
if(rand4 == rand3)
{
Start();
}
else
Destroy(this.gameObject);
}
if(GUI.Button(Rect(90,70,50,30),"wrong"))//GUI button for wrong
{
if(rand4 != rand3)
Start();
else
Destroy(this.gameObject);
}
}
*/