I have a simple object question. At least, I think this is using objects because it uses the “new” keyword to reference things. But anyway, I am making a FPS game and there are guns in it, obviously, and I want each gun to have it’s own stats and such. Here is the way I have it set now:
public class WeaponType
{
public bool weaponCanAimIn = false;
public bool weaponIsAimingIn = false;
public float weaponFireRate = 0.0f;
public float weaponDamage = 0.0f;
public int[] weaponAmmoMags = new int[5];
/*
* weaponDamge Array Indexs
* [0]: "Assault Rifle" Ammo Mags,
* [1]: "Sub-Machine Gun" Ammo Mags,
* [2]: "Handgun" Ammo Mags,
* [3]: "Sniper Rifle" Ammo Mags,
* [4]: "Shotgun" Ammo Mags
*/
public int weaponAmmoInMag = 0;
public int weaponAmmoAllowedInMag = 0;
public float weaponAccuracy = 0.0f;
public float weaponHitRange = 0.0f;
public string weaponShootType;
/*
* TYPES OF SHOOT TYPES TO CHOOSE FROM: (8 in all)
*
* FOR MELEE:
* "Melee"
*
* FOR ASSAULT RIFLES AND SUB-MACHINE GUNS:
* "Fully-Automatic",
* "Semi-Automatic"
*
* FOR HANDGUNS:
* "Semi-Automatic" (ALWAYS CHOOSE THIS FOR HANDGUNS)
*
* FOR SNIPER RIFLES:
* "Bolt-Action",
* "Semi-Automatic"
*
* FOR SHOTGUNS:
* "Pump-Action",
* "Semi-Automatic",
* "Fully-Automatic"
*/
public string weaponType;
/*
* TYPES OF GUNS TO CHOOSE FROM:
*
* "Melee"
* "Assault Rifle",
* "Sub-Machine Gun",
* "Handgun",
* "Sniper Rifle",
* "Shotgun"
*/
public string weaponName;
public Transform weaponAttackPoint;
public Transform weaponTransform;
public WeaponType (bool CanAimIn, float FireRate, float Damage, int AmmoAllowedInMag, float Accuracy, float HitRange, string ShootType, string WeaponType, string Name)
{
weaponCanAimIn = CanAimIn;
weaponFireRate = FireRate;
weaponDamage = Damage;
weaponAmmoAllowedInMag = AmmoAllowedInMag;
weaponAccuracy = Accuracy;
weaponHitRange = HitRange;
weaponShootType = ShootType;
weaponType = WeaponType;
weaponName = Name;
}
}
This works for changing weapons and upgrading stats and all, but if I want to display the stats or add an attachment, I don’t think this is the best way of doing it because I keep needing to do “weaponType = new WeaponType (stuff in here);”
Here is the way I want to do it but I am not sure if I should:
public class CurrentWeapon
{
//This is for switching weapons in player's hand.
}
public class WeaponStats
{
//Below I would declare a lot of arrays and stuff
public float[] weaponDamage = new float[35]; //I have 36 weapons
/*
Here is where I would list which array is to keep track of everything. Like this:
[0]: "M4A1" Weapon Damage
[1]: "M16A1" Weapon Damage... etc
*/
}
Is this the best way of doing things? What are some suggestions? And by the way, every class I showed is below the “main” class in the script that I created.