Hi guys
I am generating random number of objects when game starts, and destroying them after some time. Then I am showing GUI with three options(3 numbers) and user has to select the correct one(i.e how many number of objects were there).
I don’t know how to put the answer in one of the three options in random spots each time and then fill other two options with number close to the answer. (Note that objects are also getting generated randomly when game starts)
So basically what I want is if 4 objects are generated, then GUI will pop up with three option and within the three options, one will be the answer i.e 4 and other two options will be 5,6 or 3,5 etc.
Currently I am just hard coding the value as shown below.
#pragma strict
var respawn1:GameObject;
var randomcars:int;
var i:int;
var showGUI = false;
var myCam:Camera;
function Start () {
randomcars = Random.Range(1,6);
for (var i : int = 1;i <= randomcars; i++) {
Instantiate (respawn1, Vector3(i * 5, 0, 0), Quaternion.identity);
}
}
function Update (){
showGUI = (GameObject.FindWithTag("Cars") == null);
}
function OnGUI() {
if (showGUI) {
GUI.Box (Rect (myCam.pixelWidth/2-75,myCam.pixelHeight/2-45,150,90), “How many cars?”);
if (GUI.Button (Rect (myCam.pixelWidth/2-40,myCam.pixelHeight/2-25,80,20), "1")) {
if(randomcars==1){
Application.LoadLevel ("Level2");
}
}
if (GUI.Button (Rect (myCam.pixelWidth/2-40,myCam.pixelHeight/2,80,20), "2")) {
if(randomcars==2){
Application.LoadLevel ("Level2");
}
}
if (GUI.Button (Rect (myCam.pixelWidth/2-40,myCam.pixelHeight/2+25,80,20), "3")) {
if(randomcars==3){
Application.LoadLevel ("Level2");
}
}
}
}