I am trying to create a structure in which the player destroys an object (representing picking it up) and then instantiates it elsewhere (representing putting it down.
This is the code I have to pick up the object which destroys the object perfectly well:
var acorn : GameObject;
function OnTriggerStay(acorn : Collider) {
if (Input.GetKey("1") acorn.collider)
Destroy(acorn.gameObject);
}
Now I need to add to this script to prevent a player from picking up another object until he has put down the first object.
I had thought the best way to do this would be to create a variable called acornCount with an initial value of 0. But when the player picks up an object, acornCount is increased by 1.
So I tried this, but it has made the player not able to pick up any objects at all:
var acorn : GameObject;
var acornCount = 0;
function OnTriggerStay(acorn : Collider) {
if (Input.GetKey("1") acorn.collider acornCount < 1)
Destroy(acorn.gameObject);
acornCount++;
}
The script works when I remove “acornCount++;” so I assume the problem lies with that line.
I used the ammoCount variable from the FPS tutorial pt. 2 and i can’t see what I’ve done differently to mess it up.
Can anyone tell me how to make this work?