How can I "maintain" the variables of my randomly generated guns?
Hello! I've created a script that generates random stat variables for guns. There's more to this script that isn't shown, but here's a simplified version that's still the same premise...
public class RandomGun : MonoBehaviour
{
public static int gunType;
public static int maxDamage;
public static int minDamage;
public static float fireRate;
public static int maxAmmo;
public static int currentAmmo;
public void GenerateGun() //MAIN GEN SCRIPT - 1
{
GenGunType();
GenDamage(gunType);
GenFireRate(gunType);
GenAmmo(gunType);
}
void GenGunType()
{
gunType = Random.Range(1, 8);
}
void GenDamage(int type)
{
if (type == 1)
{
maxDamage = Random.Range(25, 30);
minDamage = Random.Range(5, 10);
}
if (type == 2)
{
//etc...
}
}
void GenFireRate(int type)
{
//Basically the same as above just for different stats...
}
//etc...
}
I'm then calling this script once from another script, "GunComponent" to assign its stats on Awake. I've gotten as far as having different prefab instances to have unique variables from one another. But here's where I hit the brick wall...
How do I have these variables for each randomly generated gun kept/saved after the weapon has been picked up/dropped/and having two guns in a player's inventory at the same time.
Some things to note...
Multiplayer roguelike!
All guns are gone after gameover so I don't think writing gun stats to file is the best option
Only the RandomGun variables are static, since if GunComponent's variables were static all guns would share stats ( I believe )
Two inventory slots, as I said
Held guns in player's inv. must be carried between scenes
If any other info is needed, feel free to ask. Thanks in advance for any tips!