Hi. I have 2 gameObject, let say the first one is phone and the second one is lighter. and also, i input a button ‘T’ to take.
first, i want to take the phone, and then the lighter… my issue here is both phone and lighter are gone when i press ‘T’ button. I want to take them one by one, not both of them! this is my code
private var DrawGUI = false;
function Update()
{
if(Input.GetKeyDown(KeyCode.T))
{
itemCollected();
}
}
function OnTriggerEnter (info : Collider)
{
if(info.tag == "Player")
{
DrawGUI = true;
}
}
function OnGUI ()
{
if(DrawGUI == true)
{
GUI.Label(new Rect(Screen.width*0.5-50, 200, 100, 100), "Take (T)");
}
}
function itemCollected()
{
Destroy(gameObject);
}
can’t I use a script for it? or i must separate the script each objects? thx
Start with this and we can move forward [19570-pickup+(destroy)+gameobject+one+by+one.zip|19570]
Hope this helps you out dude.
gruffy…
Just to inform you, it is a full scene with two cube in there, both tagged seperately with phone and lighter, the logic comes form the CollectStuff script found attached to the character controller.
Cheers bud:)
You could put a public variable in there that represents the number of presses required to collect your item, say numPresses. Then, in your Update function, each time you detect a key has been pressed you could decrease the numPresses variable and only call itemCollected when it reaches zero.
If you set the numPresses to 1 for your phone and 2 for your lighter (in the Inspector) you should be able to get this to do what you need.