Does anybody know how to destroy a prefab which is on the floor when i do a certain thing? I am making a FPS and have a weapon switching system and have it so that when you press ‘e’, it picks up the weapon and when you press ‘q’ it instantiates a prefab clone in front of you. I would like to make it so that when you press ‘e’, to pick up, it destroys the prefab on the floor (possibly a clone or possibly not) but i cant figure it out!
Any help is appreciated!
Thank You
- You can’t destroy prefab - you can destroy an instance.
- Since you have some sort of collision with that object (to allow picking it up on key press), you should have a reference to this object in your collision function. Your
Collider
has agameObject
parameter.