take one object

I was thinking to create a script that make me take one object, for example that's on the table, I've created the object and i've make a collision cube larger than the object and made it a trigger (that's the space in witch the player must be to press space and take the object).

I've made the script but it doesn't work because it needs to press "space" only when I hit the collision cube, not when I'm standing in it.

How can I made something like my idea?

1 Answer

1

Sounds like you may be using OnTriggerEnter to detect when the player gets close to the object. Try using OnTriggerStay, which will be called once every frame until the player leaves the trigger.

Each time OnTriggerStay gets called, test to see if the player pressed the Space key (if the object has not been picked up yet.)