I am making a top down shooter with an upgrade system.
In The game,Every bullet has a “Damage” variable which tells how much damage it will do to the player.
My question is what would be the best practice to apply the upgrade.
Should the bullet query the “Game manager” about the upgrade and change its damage accordingly
or if the gun should set the value everytime a bullet is fired ?
There’s dozens of different ways you could do this, and your method could depend on how you instantiate the bullets in the first place.
I’ll make up some theoretical variables, you can probably follow the logic and make something similar if you find it useful.
So firstly, lets do some initialisation:
**Player class**
public static int currentWeapon;
**Weapons class**
public static List<Weapon> weapon = new List<Weapon>(5);
public Weapon ()
{
public GameObject Model;
public int Damage;
}
Start()
weapon[0].Model={your weapon 1 prefab};
weapon[0].Damage=10.0f;
weapon[1]={your weapon 2 prefab};
weapon[1].Damage=20.0f;
weapon[2]={your weapon 3 prefab};
weapon[2].Damage=30.0f;
weapon[3]={your weapon 4 prefab};
weapon[3].Damage=40.0f;
weapon[4]={your weapon 5 prefab};
weapon[4].Damage=50.0f;
In your firing bullets code:
GameObject bullet = Instantiate(Weapons.weapon[Player.currentWeapon].Model);
In your OnCollision code:
OnCollission (Collider col){
shields -= col.transform.GetComponent<Weapon>().Damage;
}
This is a kinda high level overview of the logic I would suggest, not necessarily all working code as i’ve just written it off the top of my head.
But I think it’ll give you something to work on.