Пример #1
0
    public void Shoot()
    {
        if (bullets > 0)
        {
            if (!shotgun)
            {
                Straight();
            }
            if (shotgun)
            {
                Shotgun();
            }

            // Shoot Effect
            // GameObject effectInstance = (GameObject)Instantiate(fireEffect, firePoint.position, firePoint.rotation);
            // Destroy(effectInstance, 5f);

            weaponHolder.Recoil();
            bullets--;
        }
        else
        {
            if (!isReloading)
            {
                isReloading = true;
                gunMagazine.Reload();
            }
        }

        if (gunMagazine.OnWeaponUsedCallback != null)
        {
            gunMagazine.OnWeaponUsedCallback.Invoke();
        }
    }
Пример #2
0
    void Update()
    {
        if (GameManager.gameEnded)
        {
            if (currentWeapon)
            {
                currentWeapon.CancelInvoke("Shoot");
            }
            return;
        }

        if (!canShoot || currentWeapon == null)
        {
            return;
        }

        if (EventSystem.current.IsPointerOverGameObject())
        {
            return;
        }

        // Left click pressed (Shoot)
        if (currentWeapon.fireRate <= 0f)
        {
            if (Input.GetMouseButtonDown(0))
            {
                if (!currentWeapon.isReloading)
                {
                    currentWeapon.Shoot();
                }
            }
        }
        else
        {
            if (Input.GetMouseButtonDown(0))
            {
                if (!currentWeapon.isReloading)
                {
                    currentWeapon.InvokeRepeating("Shoot", 0f, 1f / currentWeapon.fireRate);
                }
            }
            if (Input.GetMouseButtonUp(0))
            {
                currentWeapon.CancelInvoke("Shoot");
            }
        }

        // Right click pressed (Reload)
        if (Input.GetMouseButtonDown(1))
        {
            if (!currentWeapon.isReloading)
            {
                currentWeapon.isReloading = true;
                gunMagazine.Reload();
            }
        }
    }