Ejemplo n.º 1
0
    /// <summary>
    /// Does attack when player has a target and wants to attack
    /// </summary>
    private void DoAttack()
    {
        if (cooldownShoot > 0)
        {
            return;                    // too soon!
        }
        if (!wantsToTarget)
        {
            return;                 // player not targeting
        }
        if (!wantsToAttack)
        {
            return;                 // player not shooting
        }
        if (target == null)
        {
            return;                 // no target
        }
        if (!CanSeeThing(target))
        {
            return;                       // target can't be seen
        }
        // spawns bullets on left and right hand
        Instantiate(bullets, handL.position, handL.rotation);
        Instantiate(bullets, handR.position, handR.rotation);

        cooldownShoot = 1 / roundsPerSecond; // rounds per second

        SoundBoard.PlayGun();                // plays gun sound

        // attack!

        camOrbit.Shake(.5f); // shakes camera slightly when shooting

        // spawns muzzle particles to look like the player is shooting a gun
        if (handL)
        {
            Instantiate(prefavMuzzleFlash, handL.position, handL.rotation);
        }
        if (handR)
        {
            Instantiate(prefavMuzzleFlash, handR.position, handR.rotation);
        }
        // trigger arm animation

        // rotates the arms up:
        armL.localEulerAngles += new Vector3(-20, 0, 0);
        armR.localEulerAngles += new Vector3(-20, 0, 0);

        // moves the arms backwards:
        armL.position += -armL.forward * .1f;
        armR.position += -armR.forward * .1f;
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Does attack when turret has a target
    /// </summary>
    private void DoAttack()
    {
        if (cooldownShoot > 0)
        {
            return;                    // too soon!
        }
        if (target == null)
        {
            return;                 // no target
        }
        if (!CanSeeThing(target))
        {
            return;                                                         // target can't be seen
        }
        Instantiate(bullets, turretMuzzle.position, turretMuzzle.rotation); // Spawns bullets

        SoundBoard.PlayGun();                                               // Plays gun sound

        cooldownShoot = 1 / roundsPerSecond;                                // Rounds per second shot

        // attack!

        //camOrbit.Shake(.5f);

        if (turretMuzzle)
        {
            Instantiate(prefavMuzzleFlash, turretMuzzle.position, turretMuzzle.rotation);               // shows muzzle flash particles
        }
        // trigger arm animation

        // rotates the arms up:
        turretHead.localEulerAngles += new Vector3(-5, 0, 0);

        // moves the arms backwards:
        turretHead.position += -turretHead.forward * .05f;
    }