eg 4 + 6 = 12…then after user clicks on right or wrong button next numbers are generating…eg 8 +4 = 6…
i want to limit or restrict or only want only 20 such equation or number…wht changes i need to do in my code…here is my code…
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);
}
}
Hope this Example helps. I do not know Javascript, So please take care of Syntax errors.
var rand1:int;
var rand2:int;
var rand3:int;
var rand4:int;
var currTry:int = 0; //Increment when click on button
var maxTry:int = 20; //check for max allowed inputs
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()
{
if(currTry < maxTry) //check if we
{
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
{
currTry++; //Increment Here
if(rand4 == rand3)
{
Start();
}
else
Destroy(this.gameObject);
}
if(GUI.Button(Rect(90,70,50,30),"wrong"))//GUI button for wrong
{
currTry++; //Increment Here Again
if(rand4 != rand3)
Start();
else
Destroy(this.gameObject);
}
}
else
{
Debug.Log("-----------------------------------MAX TRY COMPLETED-------------------------------");
///Do Something else after 20 Try Done
}
}
By using above code i want to display previous,current and next numbers or equation for eg
intially 1st equation is 5 + 4 = 10 after user clicks on right and wrong button next equation should appear
for eg 2nd equation 6 + 4 = 14
now i want to display previous as well next random eqation …hw to do …plz help?