- Home /
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.
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
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.
Your answer
Follow this Question
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