- Home /
Checking if multiple GameObjects do what one has to....
I really couldn't come up with a good title so please bear with me as ill try to explain what my problem is.I am creating a standard FPS game and (just like many other FPS games) when there's a weapon on the ground i want the player to be able to grab it and drop the one he is holding.Before i explain the way i did it (because its not working) I want suggestions on how you would make it.Basically im tracking if that gameObject is withing the screen and if the player presses "E" he picks it up.How can i track multiple gameObjects for example a room filled with AK_47 (i am now only taking the tag of the gameObject so can only target one of them at a time as i am checking if that one is within the screen limit).Its been a lond day and im very tired so I apologise in advance if all i just typed makes no sense :P i really need some help.In brief, whats the best way to track which weapon im next to or at least how to track multiple of that one weapon.
Answer by cjdev · Jun 10, 2016 at 02:01 PM
You could try using a collider on each weapon and when the collision happens register that weapon as valid to pick up. If you need to pick it up anywhere on screen you can cast a ray out to the colliders instead of using the collision with a character controller.
Thanks for the response. I found another great way to overcome the issue by giving all the guns (all variations models, not of a certain kind) one tag and then looping through all of those and finding the ne closest to me, if that gun was within screen space and a small distance from the plahyer i grab it. I didnt want to add colliders to all the guns in my scene for performance issues just leaving the way i did it here for future reference .Thanks again for your reply :)!
Your answer
Follow this Question
Related Questions
Problem with multiple gameobjects using same script. 0 Answers
[C#] Translate.position a lot of gameobjects at once (due to velocity limitations) 0 Answers
Destroying objects with the same name that are touching eachother. 1 Answer
OnTriggerEnter() not firing for mutliple objects 0 Answers
how to detect an gameobject on mouse click using raycast 1 Answer