- Home /
I need help with my script
I'm making a normal FPS game and some of my scripts are saying " found ''." and I know this is a simple problem but i need some help. Also, if someone could help me, how do you make a "gun" show up on the screen?
Thanks, John
Could you be more specific, please? What do these scripts do? How do you want the gun to show up on the screen - in a GUI, as a 3D model, etc.?
well i got it to show up but now i need it to move with the camera and also i need a crosshair
Answer by Zylar · Jan 07, 2011 at 05:27 AM
Adding the Crosshair
First step is to add in the crosshair.
- First make a empty GameObject and rename it as "Crosshair GUI" or equivalent.
- Add in the GUI Texture component. [ Component -> Rendering -> GUITexture ]
- Place your crosshair texture into the component and make all necessary adjustments. Don't worry about its placement just yet if you're going to have the crosshair directly in the middle of the screen, we will come back and adjust it later.
Note: Do not make the crosshair a child of anything that moves.
Adding the Gun
Getting the gun to follow the camera is just as easy as getting your camera to follow your player.
- All that needs to be done is to make the gun a child of your Main Camera. Any changes to the camera's transform will trickle down to the gun and move it as well. Of course, make the proper adjustments to the gun so it looks like the player is holding the gun.
Avoiding a Clipped Gun
This will have the gun still visible even though it passes though walls and objects.
- Add a new layer and name it "Gun Layer" or equivalent.
- Place your gun in the gun layer.
- Create a new camera and rename it "Gun Camera" or equivalent. [ GameObject -> Create Other -> Camera ]
- Remove the gun camera's audio listener, flare layer, and gui layer components. They will be handled by the Main Camera.
- Make the camera component's clear flags Depth Only, culling mask only the gun layer, and change the depth to be higher than the main camera's.
Adjusting the Crosshair
This is a pretty neat trick to finding the center of your screen, and thus moving your crosshair to the right place.
- Switch to the game view. The larger your game view the more accurate your placement will be.
- On your Gun Camera change its field of view to maximum. This will force the perspective to squeeze your gun directly into the center of the screen! My gun turned into one pixel.
- Now using your gun as the center, position your crosshair so that its center is pointed exactly at the single pixel (The gun). Also, because of the gun layer camera, the gun will be drawn on top of the crosshair. So long as the gun's single pixel can stand out when compared to the crosshair, you will see it.
- Once done placing the crosshair, go back and return the gun camera's field of view to normal (Roughly 60).
And there you have it! By now you should have:
- A crosshair centered exactly at the middle of the screen.
- A gun that follows the camera, and doesn't get obscured by objects the player would use as cover.
Answer by BinaryCaveman · Nov 13, 2010 at 12:53 AM
For a crosshair, you could create a simple GUI Texture. To do this,
- Select the crosshair image
- Click GameObject>Create Other>GUI Texture
- Adjust the GUI Texture as necessary in the inspector
To make the gun GameObject move with the camera, you want to make it a child of the camera (or vice versa) in the hierarchy.
Hope this helps!
Answer by Adam Rademacher · Nov 13, 2010 at 01:03 AM
If a script is telling you ' found "." ' it means that you have an error in syntax. Usually, you've missed a semicolon or parenthesis somewhere and made the compiler get confused. If you post a code sample I can help you fix the syntax.
Your answer
Follow this Question
Related Questions
FPS Gun Attached To Camera Weirdness 3 Answers
Need help with bullet/gun scripting 3 Answers
NullReferenceException on my gunscript 1 Answer
How do I render something specific to a camera? 2 Answers
Fps Arm moves fase 2 Answers