Questions about a Weapon Switch script.

using UnityEngine;

    public class SwitchMethodOne : MonoBehaviour {
    
    public GameObject currentWeapon;
    public GameObject[] myWeapons = new GameObject[]
    public int currentWeaponIndex = 0;
    
    public void Awake() {
    myWeapons = new GameObject[Enum.GetValue(typeof(myWeapons)).Length];
    }
    
    void Update() {
    if(Input.GetButtonDown("KeyCode.LeftShift")) {
    currentWeaponIndex = (currentWeaponIndex + 1) % myWeapons.Length;
    currentWeapon = weaponArray[currentWeaponIndex];

Questions:

What is the purpose of “(currentWeaponIndex + 1) % myWeapons.Length;?”

 . Currently, "currentWeaponsIndex" is equal to 0, so why are we just adding 1 to it?

(In reference to first question) why are we getting the remainder of 1/myWeapons.Length?
. “% myWeapons.Length;”

What is happening here, is a bit of error checking and defensive programming. It makes it so the user cannot select a weapon out of range of the weapon collection, instead it loops around the list. So if the user is at the end of the list and presses shift, they go to the first weapon.

The mod operator (%) is a great way to make sure a value stays within the bounds of another value.