Ejemplo n.º 1
0
    private void Update()
    {
        if (MenuController.Paused)
        {
            return;
        }

        PointWeaponAtCrosshair();

        if (Input.GetButtonDown("Fire1"))
        {
            wielder.FirePrimary(false);
        }
        else if (Input.GetButton("Fire1"))
        {
            wielder.FirePrimary(true);
        }

        if (Input.GetKeyDown(KeyCode.R))
        {
            wielder.Reload();
        }

        // Test weapon switching code - if this is a real thing we want do this better with a real input button
        if (Input.GetKeyDown(KeyCode.E))
        {
            ChangeToWeapon(curWeaponIndex + 1);
        }
    }
Ejemplo n.º 2
0
    public bool PrimaryFire(WeaponWielder firer, bool tryAuto)
    {
        if ((isAuto == tryAuto) && cooldownClock >= shotCooldownTime && !reloading)
        {
            if (curAmmo == 0)
            {
                firer.Reload();
                return(false);
            }

            float spreadLinearMax = Mathf.Sin(Mathf.Deg2Rad * (spreadAngle / 2));

            for (int i = 0; i < projectilesPerShot; ++i)
            {
                float   spreadLinear = Random.Range(0, spreadLinearMax);
                Vector3 fireVec      = Quaternion.AngleAxis(Random.Range(0, 360), transform.forward) * (transform.forward + (transform.up * spreadLinear));

                GameObject projectile = GameObject.Instantiate(projectilePrefab);
                Projectile proj       = projectile.GetComponent <Projectile>();
                if (proj == null)
                {
                    Debug.LogError("Tried to shoot not a projectile");
                }

                projectile.transform.position = transform.position + transform.forward;
                proj.direction = fireVec;
            }

            curAmmo--;
            cooldownClock = 0;

            return(true);
        }
        else
        {
            return(false);
        }
    }