Skip to content

Ammo Weapon

Apart from the default/basic weapon the player will also be able to pick much stronger weapons, such as a machine gun to rapidly fire bullets and canon to deal big damage to enemies with one bullet. However, these stronger weapons need to have a limited amount of ammunition, otherwise these types of weapons would be way to strong and make the game too easy to complete.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AmmoWeapon : BasicWeapon
{
    private int _ammo;

    public int Ammo
    {
        get => _ammo;
        set
        {
            _ammo = value;
            if (_ammo <= 0)
                //Delete
                return;
        }
    }

    public AmmoWeapon(ProjectileFactory factory, float cooldown, int ammo) : base(factory, cooldown)
    {
        Ammo = ammo;
    }

    public override void Fire(IWeaponUser user)
    {
        base.Fire(user);
        Ammo--;
        Debug.Log(Ammo);
    }

    public override bool CanFire(IWeaponUser user) => base.CanFire(user) && Ammo > 0;
}

Last update: May 30, 2023