Hi everyone, I have a slight problem. I have this code that will show a list words of items. Now once you collect the item it will display an X saying that you have collect this item and also give you a random number. Problem is that once I collect one item, it says I collect all of them and generate the same random number through the list. How do I fix that? Is this suppose to be an array? and if so can you please guide me through it?
var itemOne : GameObject;
var itemTwo : GameObject;
var itemThree : GameObject;
var itemFour : GameObject;
var checkOff;
var itemsToWin : int = 8;
var nameItem;
private var canHover : boolean = false;
private var digit : int;
private var randomItem : String;
function Start()
{
Screen.lockCursor = true;
}
function Update()
{
var fwd = transform.TransformDirection(Vector3.forward);
var hit : RaycastHit;
if (Physics.Raycast(transform.position, fwd, hit))
{
if(hit.distance <= 5.0 && hit.collider.gameObject.tag == "pickup")
{
canHover = true;
if(Input.GetMouseButtonDown(0))
{
Destroy(itemOne);
digit = Random.Range(0,10);
checkOff = "X";
//Do something!
}
}
else
{
canHover = false;
}
if(hit.distance <= 5.0 && hit.collider.gameObject.tag == "pickupb")
{
canHover = true;
if(Input.GetMouseButtonDown(0))
{
Destroy(itemTwo);
digit = Random.Range(0,10);
checkOff = "X";
//Do something!
}
}
else
{
canHover = false;
}
/*if(hit.distance <= 5.0 && hit.collider.gameObject.tag == "pickupc")
{
canHover = true;
if(Input.GetMouseButtonDown(0))
{
Destroy(itemThree);
papers +=1;
//Do something!
}
}
else
{
canHover = false;
}
if(hit.distance <= 5.0 && hit.collider.gameObject.tag == "pickupd")
{
canHover = true;
if(Input.GetMouseButtonDown(0))
{
Destroy(itemFour);
papers +=1;
//Do something!
}
}
else
{
canHover = false;
}*/
}
}
function OnGUI()
{
if(canHover == true)
{
GUI.Box(Rect(Screen.width / 2 - 100, Screen.height / 2 - 100, 150, 20), "Pick up!");
}
GUI.Box( Rect( (Screen.width/2)-600, 350, 180, 180 ), "" + checkOff + " Candles " + digit);
GUI.Box( Rect( (Screen.width/2)-600, 330, 180, 180 ), "" + checkOff + " Television " + digit);
}
↧