示例#1
0
    // Update is called once per frame
    void Update()
    {
        int previousSelectedWeapon = weaponHolder.selectedWeapon;

        for (int i = 0; i < keyCodes.Length; i++)
        {
            if (Input.GetKeyDown(keyCodes[i]))
            {
                int numberPressed = i;
                weaponHolder.selectedWeapon = numberPressed;
                weaponHolder.SelectWeapon();

                if (OnWeaponUIUsedCallback != null)
                {
                    OnWeaponUIUsedCallback.Invoke();
                }
            }
        }

        if (previousSelectedWeapon != weaponHolder.selectedWeapon)
        {
            GunMagazine.instance.StopReloading();
            if (GunMagazine.instance.OnWeaponUsedCallback != null)
            {
                GunMagazine.instance.OnWeaponUsedCallback.Invoke();
            }
        }
    }
示例#2
0
    public IEnumerator ReloadDelay()
    {
        reloadTimer.value = 1f;
        while (reloadTimer.value >= 0.05f)
        {
            yield return(new WaitForSeconds(Time.deltaTime));

            reloadTimer.value = reloadTimer.value - (Time.deltaTime / weaponHolder.currentWeapon.reloadTime);
        }
        weaponHolder.SelectWeapon();
        weaponHolder.currentWeapon.Reload();

        reloadTimer.gameObject.SetActive(false);
    }