Weapon Reload Animation/Script

Hello all, I am working on building a FPS game that will be Single player to start. I am looking for a Good (Bug Free) Magazine Reload Script/Animation that I can use in my game. if anyone has knolage in this field of game Development (I am new to this Scene) Please give me some advice or a full line of Code that i could use to test and make a reload happen in a weapon test.

Thanks, Mike.

You’re just not going to find a complete script to cause your custom game to suddenly magically grow a reload feature.

You’ve played FPS games before I presume. Decompose in your head the elements involved in a weapon that fires discrete projectiles. Here’s what I come up with:

  • count of bullets in the gun (display this as a count on the screen)
  • maximum count it can hold (display this as a count too)
  • pulling the trigger
    → if you have bullets, print “fire” and make a fire button “use up” a bullet
    → if you have no bullets, print “click”
  • reloading (make a button restore the bullets to some amount)
    → display the “cooldown” time it takes to reload during which the player cannot fire
    → disable firing during the cooldown phase.

Once you understand ALL of the above and can make it work properly just using Unity UI elements (buttons and text), only then do you bother to even try and show an animation happen while you reload.

I am not looking for anything fancy at the moment. All i am looking to do is do a Script or animation that it’s. just to test to see if it will be buggy and whatnot. I have a team i have put together of friends with 10+ experience in Game Development. I’m just the end guy looking over things and proof checking everything to make sure it’s what my vision is. I have a team of 15 Friends. Even thought we are 15 strong i am going to take the time to make sure the game looks and feels good. so a 4 5 year development span is in the works.

Thanks again, Mike.

My next video is about a generic inventory script. The first implementation is for reloading your weapon.
Check the spoiler for a part of the reloader script.
The playlist is in my sig below. I expect to have the movie ready in 2 days. This will give you a solid reloading script.

WeaponReloader

    [SerializeField]int maxAmmo;
    [SerializeField]float reloadTime;
    [SerializeField]int clipSize;
    [SerializeField]Container inventory;
  
    public int shotsFiredInClip;
    bool isReloading;
    System.Guid containerItemId;
  
    public int RoundsRemainingInClip {
        get {
            return clipSize - shotsFiredInClip;
        }
    }
  
    public bool IsReloading {
        get {
            return isReloading;
        }
      
    }
  
    void Awake() {
        containerItemId = inventory.Add(this.name, maxAmmo);
    }
  
    public void Reload() {
        if(isReloading)
            return;
      
        isReloading = true;
        int amountFromInventory = inventory.TakeFromContainer(containerItemId, clipSize - RoundsRemainingInClip);
      
        GameManager.Instance.Timer.Add(() => {
            ExecuteReload(amountFromInventory);
        }, reloadTime);
      
    }
  
    private void ExecuteReload(int amount) {
        isReloading = false;
        shotsFiredInClip -= amount;
    }
  
  
    public void TakeFromClip(int amount) {
        shotsFiredInClip += amount;
    }

And a part of the container script, which can be used for inventories, but also for other containers where you would carry or transport other items.

Container

public class Container: MonoBehaviour {

    public List<ContainerItem> items;

    /// <summary>
    /// Add a new valid / available container item
    /// </summary>
    /// <param name="name">Name.</param>
    /// <param name="maximum">Maximum.</param>
    public System.Guid Add(string name, int maximum) {
        items.Add(new ContainerItem { Name = name, Maximum = maximum });
        return items.Last().Id;
    }

    /// <summary>
    /// Takes from container.
    /// </summary>
    /// <param name="id">Identifier.</param>
    /// <param name="amount">Amount.</param>
    public int TakeFromContainer(System.Guid id, int amount) {
        var element = GetItemById(id);
        if(element == null)
            return -1;
        return element.Get (amount);
    }

    /// <summary>
    /// Puts to container.
    /// </summary>
    /// <param name="id">Identifier.</param>
    /// <param name="amount">Amount.</param>
    public void PutToContainer(System.Guid id, int amount) {
        var element = GetItemById(id);
        if(element == null)
            return;
        element.Put(amount);
    }

    private ContainerItem GetItemById(System.Guid id) {
        return items.Where(x => x.Id == id).FirstOrDefault();
    }

}