- Home /
Pick up and Drop a gun
Hello. I want to make a FPS game and I need a script for pick up and drop gun. Or when i have a arm, i want to press e and drop my gun and pick up another gun from the ground. C# or JavaScript. Prefer C#.
Answer by Ensaba · Nov 18, 2017 at 11:11 PM
There are multiple ways to implement this feature.
First add a collider (define the radius which define how far you will be able to pick the gun) and define a tag to your gun game object, i.e. tag = gun. Now on your player, attach (or in the gun object) a script with OnCollisionEnter. Once you collide, turn on a flag (bool) and check on update for a hotkey, i.e. if (Input.GetKeyDown("space") && flag) If true, add the gun to your player.
Most important, stop asking for scripts and learn to to implement them. That is not game development.
Sometime object we are holding is gone phase through the floor when i drop it why?
Your answer
Follow this Question
Related Questions
pick up ammo from specific gun? 1 Answer
Parenting 1 object/Removing child/ pick up 1 Answer
Why is my gun stretching out when I pick it up? 2 Answers
Bullet Drop With Raycast 4 Answers
Refer to object class is attached to 1 Answer