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
-1
Question by buckethead3495 · Nov 29, 2010 at 10:55 PM · fpsguitextureweaponcrosshair

Different crosshairs for different weapons ?

I was wondering if it was possible to somehow apply a different crosshair for each type of weapon in my game (like a shotgun crosshair would look different from an assault riffle and so on) if it is possible, how would I do this? I already have all the crosshairs made and I know how to add a crosshair to the actual game I'm just unsure of how to add a different one for each weapon?

Thanks in advance to anybody that can help.

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Proclyon · Nov 30, 2010 at 09:22 AM

Some form of controller will need to keep track of either crosshair state and link it to which gun is going to be present (None, Gun_A, Gun_B, Gun_C ...) or the other way round. Seeing as you may need to interact with the environment or just want a crosshair by default (maybe for throwing stuff with physics I have no idea what the game does from just the question) this could be a good idea.

You could also let the character itself be the statemachine and have his/her/it's gunlist automatically load a crosshair texture based on a codewise mathc with the gun ID Type or Tag. if gun from list a crosshair texture is value from 0th from crosshair list if gun from list b crosshair texture is value from 1st from crosshair list

What you definatly will need is:

Something that knows when what gun is equipped OR which crosshair is active A response in (probably the update method/function) which changes the gun to match the crosshair or vice versa.

Breaking it down in smallest possible components

Get current state Set value to match current state

just don't keep loading texture every frame so much better would be

Get current state Set value to match current state if state changed

Live loading per frame is one of the quickest way to lose 99% FPS

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
1

Answer by diabloroxx · Nov 30, 2010 at 12:01 AM

Set a mode for each weapon. In case you use different Weapon script, then use the OnGUI() in each to appropriately modify the texture. I have been switching textures based on an If Condition. Eg: 1. Set booleans for mode (MissileLauncher / Rifle) 2. If (boolean) , update the Crosshair texture.

Alternatively, you can also use a Switch case if you have more than 2 weapons to deal with.

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

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

change weapon only one player in network 0 Answers

Simple GUI In game 1 Answer

C# How to apply damage to enemys? Shooter 0 Answers

Machine Gun aim to crosshair 3 Answers

Make crosshairs disappear while aiming 0 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