Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by John 20 · Nov 12, 2010 at 03:44 AM · camerafpsguitexturegun

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

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image BinaryCaveman · Nov 12, 2010 at 04:19 AM 0
Share

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.?

avatar image John 20 · Nov 12, 2010 at 06:31 AM 0
Share

well i got it to show up but now i need it to move with the camera and also i need a crosshair

3 Replies

· Add your reply
  • Sort: 
avatar image
1

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:

  1. A crosshair centered exactly at the middle of the screen.
  2. A gun that follows the camera, and doesn't get obscured by objects the player would use as cover.
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bob 9 · Feb 20, 2011 at 10:41 PM 0
Share

this worked perfectly, thanks i needed help with this too

avatar image
0

Answer by BinaryCaveman · Nov 13, 2010 at 12:53 AM

For a crosshair, you could create a simple GUI Texture. To do this,

  1. Select the crosshair image
  2. Click GameObject>Create Other>GUI Texture
  3. 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!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image John 20 · Nov 28, 2010 at 06:09 AM 0
Share

thanks but i got it now

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges