public void SetWeapon(int next, int prev)
    {
        if (CheckWeapon())
        {
            WeaponSystem weapon = GetCurWeapon();
            weapon.CancelReload();
            SetWeaponActive(weapon, false);
        }
        int cur = curWeapon;

        curWeapon  = next;
        prevWeapon = prev;

        WeaponSystem nextWeapon = GetCurWeapon();

        if (cur != next)
        {
            LoadoutManager.instance.SwitchWeapon(cur, next);
        }
        SetWeaponActive(nextWeapon, true);

        LoadoutManager.instance.UpdateWeapon(nextWeapon.GetCurAmmo(), nextWeapon.data.ammo);
    }
    // Update is called once per frame
    void Update()
    {
        if (CheckWeapon())
        {
            WeaponSystem weapon = GetCurWeapon();

            if (Controls.instance.GetFireDown())
            {
                canFire = true;
            }
            if (Controls.instance.GetFireUp())
            {
                canFire = false;
            }

            if (switching)
            {
                if (nextWeapon == curWeapon)
                {
                    weapon.transform.position         = Vector3.Lerp(defaultWeaponPos.position, defaultWeaponPos.position - Vector3.up * .2f, switchTimer / weapon.data.switchTime);
                    weapon.transform.localEulerAngles = Vector3.Lerp(defaultWeaponPos.localEulerAngles, defaultWeaponPos.localEulerAngles + Vector3.right * 30f, switchTimer / weapon.data.switchTime);

                    switchTimer -= Time.deltaTime;
                    if (switchTimer <= 0)
                    {
                        weapon.SwitchingWeapon(false);
                        switching = false;
                        weapon.transform.position         = defaultWeaponPos.position;
                        weapon.transform.localEulerAngles = defaultWeaponPos.localEulerAngles;

                        if (weapon.GetCurAmmo() == 0 && !weapon.IsReloading())
                        {
                            weapon.Reload();
                        }
                    }
                }
                else
                {
                    weapon.transform.position         = Vector3.Lerp(defaultWeaponPos.position - Vector3.up * .2f, defaultWeaponPos.position, switchTimer / weapon.data.switchTime);
                    weapon.transform.localEulerAngles = Vector3.Lerp(defaultWeaponPos.localEulerAngles + Vector3.right * 30f, defaultWeaponPos.localEulerAngles, switchTimer / weapon.data.switchTime);

                    switchTimer -= Time.deltaTime;
                    if (switchTimer <= 0)
                    {
                        weapon.SwitchingWeapon(false);
                        SetWeaponActive(weapon, false);

                        curWeapon = nextWeapon;
                        weapon    = GetCurWeapon();
                        weapon.SwitchingWeapon(true);
                        SetWeaponActive(weapon, true);
                        switchTimer = weapon.data.switchTime;

                        weapon.transform.position         = defaultWeaponPos.position - Vector3.up * .2f;
                        weapon.transform.localEulerAngles = defaultWeaponPos.localEulerAngles + Vector3.right * 30f;
                        LoadoutManager.instance.UpdateWeapon(weapon.GetCurAmmo(), weapon.data.ammo);
                    }
                }
            }
            else if (usingGrenade)
            {
                float scaledTimer = Mathf.Abs(throwGrenadeTimer - throwGrenadeTime * .5f) * 4f - throwGrenadeTime;
                weapon.transform.position         = Vector3.Lerp(defaultWeaponPos.position - Vector3.up * .1f, defaultWeaponPos.position, scaledTimer / throwGrenadeTime);
                weapon.transform.localEulerAngles = Vector3.Lerp(defaultWeaponPos.localEulerAngles + Vector3.right * 20f, defaultWeaponPos.localEulerAngles, scaledTimer / throwGrenadeTime);

                if (!grenadeThrown && throwGrenadeTimer < throwGrenadeTime - grenadeReleaseDelay)
                {
                    if (grenades.Length > activeGrenade && grenades[activeGrenade] != null)
                    {
                        Instantiate(grenades[activeGrenade], secondaryWeaponPos.position, secondaryWeaponPos.rotation);
                    }
                    grenadeThrown = true;
                }

                throwGrenadeTimer -= Time.deltaTime;

                if (throwGrenadeTimer <= 0)
                {
                    usingGrenade = false;
                }
            }
            else if (Controls.instance.GetGrenade())
            {
                ThrowGrenade();
            }
            else
            {
                Vector3 reticleCenter = Quaternion.AngleAxis(5, Camera.main.transform.right) * Camera.main.transform.forward;

                RaycastHit hit;
                if (Physics.Raycast(Camera.main.transform.position, reticleCenter, out hit, 100, ~0, QueryTriggerInteraction.Ignore))
                {
                    weapon.RotateWeapon(hit.point);
                }
                else
                {
                    weapon.RotateWeapon(weapon.transform.position + reticleCenter);
                }

                if (weapon.IsReloading() && reloadAnimTimer == -1)
                {
                    reloadAnimTimer = 0;
                }
                if (weapon.IsReloading() && reloadAnimTimer >= 0)
                {
                    weapon.transform.position         = Vector3.Lerp(defaultWeaponPos.position, defaultWeaponPos.position - Vector3.up * .1f, reloadAnimTimer / reloadAnimTime);
                    weapon.transform.localEulerAngles = Vector3.Lerp(defaultWeaponPos.localEulerAngles, defaultWeaponPos.localEulerAngles + Vector3.right * 20f, reloadAnimTimer / reloadAnimTime);
                    reloadAnimTimer = Mathf.Clamp(reloadAnimTimer + Time.deltaTime, 0, reloadAnimTime);
                }
                if (!weapon.IsReloading() && reloadAnimTimer >= 0)
                {
                    reloadAnimTimer = -1;
                }

                if (canFire)
                {
                    if (weapon.data.semiAuto && weapon.Ready())
                    {
                        canFire = false;
                    }
                    StartCoroutine(weapon.Fire());
                }
                if (Controls.instance.GetReload())
                {
                    weapon.Reload();
                }
                if (Controls.instance.GetSwitch())
                {
                    Switch(weapon, false);
                }
                else if (Controls.instance.GetSwitchToSidearm())
                {
                    Switch(weapon, true);
                }
            }
        }

        if (Controls.instance.GetInteractDown())
        {
            interacting = true;
        }

        if (interacting && Controls.instance.GetInteract())
        {
            Swap();
        }
        else
        {
            interactTimer = 0;
            interacting   = false;
        }

        int grenadeSwitch = Controls.instance.LeftRightArrow();

        if (!usingGrenade && grenadeSwitch != 0)
        {
            int looper = 0;
            do
            {
                activeGrenade = (activeGrenade + grenadeSwitch + activeGrenades.Length) % activeGrenades.Length;
            } while (!activeGrenades[activeGrenade] && looper++ < activeGrenades.Length);
            if (activeGrenades[activeGrenade])
            {
                HUDManager.instance.UpdateGrenadeSelection(activeGrenade);
            }
        }
    }