So I’m making a game where I want to be able to switch weapons. But, the twist is. I don’t want different objects in front of my camera as guns, I wan’t one single object, that can switch damage, fireRate, type of weapon, etc.
- The problem is, I don’t know how to go about this. I don’t know where to start. Does anyone have any ideas to how I could do this?
What I want to be able to do:
- Either use buttons (1,2,3…) or a gui to swap weapons.
- When I swap weapons, I want the same gameobject, but changed variables like fireRate and type of weapon (like from rifle to sniper or pistol)
I’m not asking for a full script, I just need ideas for how to go about this
Easy enough, in your script (or in some WeaponsManager script) just have a number of configurations in an array. Then store either the current information or an index to the current information and use that when calculating fire rate etc.
Simple example (written off the top-of-my-head here and not checked so may be full of errors). Extending this so that each character has an index or reference to the weapon they are using would be sensible.
public class WeaponManager : MonoBehaviour
public class WeaponConfiguration
public float FireRate;
public float DamageCaused;
public WeaponConfiguration WeaponConfigurations;
public int CurrentIndex = 0;
public void SwitchWeapon(int index)
//TODO: Check that the index is actually valid!
CurrentIndex = 0;
public float GetFireRate()
public float GetDamage()