示例#1
0
    public void HandleReloading(bool reload)
    {
        // TODO: Convert Gun To machine-gun

        if (reload)
        {
            Reload();
        }

        if (IsReloading)
        {
            _reloadTimer -= Time.deltaTime;

            if (_reloadTimer < 0)
            {
                AmmoInClip   = clipSize;
                _reloadTimer = 0;
                _fireTimer   = 0;

                AmmoDisplaySystem.SetAmmo(AmmoInClip);
                _reloadDisplayHolder.gameObject.SetActive(false);
            }

            float t = (reloadTime - _reloadTimer) / reloadTime;

            _reloadDisplayFill.localScale = new Vector3(t, 1, 1);
        }
    }
示例#2
0
    private void FireGun()
    {
        // Check to see if you can fire
        if (IsReloading || AmmoInClip == 0)
        {
            return;
        }

        // Remove a bullet from the clip
        AmmoInClip--;
        AmmoDisplaySystem.SetAmmo(AmmoInClip);
        _fireTimer += FireRate;

        // Create a bullet with the angle of the gun
        float angle = _gunHolder.rotation.eulerAngles.z;

        angle += Random.Range(-bulletSpray, bulletSpray) * 0.5f;
        Bullet prefab = Resources.Load <Bullet>("Prefabs/Bullets/PlayerBullet");
        Bullet bullet = Instantiate(prefab, _bulletSpawn.position, Quaternion.AngleAxis(angle, Vector3.forward));
    }