how to limit the random number.....i.e currently random numbers are appearing....

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);
  
  }
  }

So many …

First : don’t use start as a procedure.

Create one new function that create the equation.

Then create a counter :
var nbTry : int = 0;

Then After each answer, add 1 to the counter :
nbTry++

Then add a test to check if nbTry is equal to the maximum number of try. If not draw the equation, if it’s equal print somethings like “End”

sidhesh, you keep creating threads for small questions pertaining to the same thing:

http://forum.unity3d.com/threads/161084-how-to-internally-calculate-random-number....i-am-implementing-game-like-braintuner2.

http://forum.unity3d.com/threads/160987-how-to-generate-operators-such-as-randomly.......can-we-use-random.range-

http://forum.unity3d.com/threads/160900-i-am-using-random.range-function...its-generating-random-number..but-its-nt-appearing

That’s just in the last 24 hours. You also have 3 more pertaining to this very same subject from a week ago.

Why not keep it all in one thread so the progression of help can be referenced upon.

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
}

  }

thnx alot MicroEyes…it works …

I am Glad, this helps you.

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?