How would I get an object from the centre of the screen?


I’m making an FPS and I have the basic controls and everything set up, but I wanted to know something. I’ve used the code:

Screen.lockCursor = true;

So my mouse is now centered and locked in the middle of the screen. I wanted to know how I could get an object that was within a certain distance of the CharacterController (the player) and in the center of the screen where the mouse was? Then, when the object passes all of these and the player presses “E” (or the USE button), then the object does something.

The concept is kind of similiar to that of Source games like Half-Life 2, Garry’s Mod and Team Fortress 2 where you push your “USE” button and something happens, like a door opens up, or whatnot.

Thanks in advance! :slight_smile:


these scripts Activate-Deactivate-Objects-on-Click-or-other-Input should do exactly what you want, I wrote it for any mouse position so it will work with your locked to middle as well. Good luck!