1.新增了武器类
public enum WeaponType
{
Pistol,
Revolver,
AutoRifle,
Shotgun,
Rifle
}
[System.Serializable] //将这个类在窗口中显示
public class Weapon
{
public WeaponType weaponType;
public int ammo;
public int maxAmmo;
public bool canShoot()
{
return HaveEnoughBullets();
}
private bool HaveEnoughBullets()
{
if (ammo > 0)
{
ammo--;
return true;
}
return false;
}
}
2.增加了武器槽
[Header("Inventory")] //武器槽
[SerializeField] private List<Weapon> weaponSlots;
[SerializeField] private int maxSlots;
//在武器槽中装备武器
private void EquipWeapon(int i)
{
currentWeapon = weaponSlots[i];
}
3.实现了简单的丢弃武器功能
//丢弃武器
private void DropWeapon()
{
//只有武器大于等于2的时候,才能丢武器
if(weaponSlots.Count <= 1)
{
return;
}
weaponSlots.Remove(currentWeapon);
currentWeapon = weaponSlots[0];
}
4.实现了简单的拾取武器功能
private void OnTriggerEnter(Collider other)
{
other.gameObject.GetComponent<PlayerWeaponController>()?.PickUpWeapon(weapon);
}
//捡起武器
public void PickUpWeapon(Weapon newWeapon)
{
if(weaponSlots.Count >= maxSlots)
{
return;
}
weaponSlots.Add(newWeapon);
}