How to make a list of objects visible in Unity Inspector?

1 day ago 7
ARTICLE AD BOX

I'm trying to create sort of a weapons database for a game in C#.

I have already defined the properties that each weapon should have, so it's easy to keep adding weapons.

But I'm having a hard time trying to find a way to [SerializeField] a variable that let me select a weapon from all the available weapons.

The purpose is to attach this script to a gameObject that the player can interact with and "read" the weapon properties of the selected weapon (selected by the Unity Inspector).

This is my current code for defining weapons:

public class WeaponList : MonoBehaviour { public class WeaponProperties { public int weaponDamage; public int weaponMaxAmmo; public float weaponReloadTime; public float weaponCadence; public float weaponLenght; private string weaponID; public string WeaponID; public int weaponMagSize; public WeaponProperties(string WeaponID, int WeaponDamage, int WeaponMaxAmmo, int WeaponMagSize, float WeaponReloadTime, float WeaponCadence, float WeaponLenght) { weaponDamage = WeaponDamage; weaponMaxAmmo = WeaponMaxAmmo; weaponReloadTime = WeaponReloadTime; weaponCadence = WeaponCadence; weaponLenght = WeaponLenght; weaponMagSize = WeaponMagSize; weaponID = WeaponID; } }; public WeaponProperties pitola = new WeaponProperties(WeaponID: "Pitola", WeaponDamage: 1, WeaponMaxAmmo: 24, WeaponMagSize: 6, WeaponReloadTime: 3,WeaponCadence: 0.6f, WeaponLenght: 0.1f); public WeaponProperties rifle = new WeaponProperties(WeaponID: "Rifle", WeaponDamage: 3, WeaponMaxAmmo: 24, WeaponMagSize: 10, WeaponReloadTime: 3, WeaponCadence: 1.0f, WeaponLenght: 0.1f);
Read Entire Article