///////////////////////////////////////////////////////////
    // fire the current weapon when player presses the left
    // mouse button. this temporarily disables the 'Crouch' and
    // 'Run' states on the current weapon
    ///////////////////////////////////////////////////////////
    protected void InputFire()
    {
        // fire button pressed / held down
        if (Input.GetMouseButton(0))
        {
            if (CurrentWeapon != null)
            {
                // if firing while crouching or running, point the weapon
                // straight forward
                if (CurrentWeapon.StateEnabled("Crouch"))
                {
                    CurrentWeapon.SetState("Crouch", false);
                }
                if (CurrentWeapon.StateEnabled("Run"))
                {
                    CurrentWeapon.SetState("Run", false);
                }

                // fire if we have a shooter component and the mouse cursor
                // is not visible
                if (CurrentShooter != null && LockCursor)
                {
                    CurrentShooter.Fire();
                }

                // TIP: to play a conventional animation upon firing (typically
                // used for melee weapons) uncomment one of the lines below
                // (see the Unity docs for more available methods & parameters).
                //CurrentWeapon.animation.Play();									// play the default animation
                //CurrentWeapon.animation.Play("your_animation");					// play the animation named 'your_animation' and stop all other animations in the same layer
                //CurrentWeapon.animation.Play("your_animation", PlayMode.StopAll);	// play 'your_animation' and stop all other animations
                //CurrentWeapon.animation.CrossFade("your_animation", 0.2f);		// fade in 'your_animation' and fade out all other animations over 0.2 seconds
            }
        }

        // fire button released
        if (Input.GetMouseButtonUp(0))
        {
            // schedule to reenable 'Crouch' and / or 'Run' in half a second
            ReenableWeaponStatesIn(0.5f);

            // disregard refire delay when firing with no ammo
            if (CurrentShooter != null)
            {
                if (CurrentShooter.AmmoCount == 0)
                {
                    CurrentShooter.NextAllowedFireTime = Time.time;
                }
            }
        }
    }
Esempio n. 2
0
    ///////////////////////////////////////////////////////////
    // fire the current weapon when player presses the left
    // mouse button. this temporarily disables the 'Crouch' and
    // 'Run' states on the current weapon
    ///////////////////////////////////////////////////////////
    protected void InputFire()
    {
        // fire button pressed / held down
        if (Input.GetMouseButton(0))
        {
            if (CurrentWeapon != null)
            {
                // if firing while crouching or running, point the gun
                // straight forward
                if (CurrentWeapon.StateEnabled("Crouch"))
                {
                    CurrentWeapon.SetState("Crouch", false);
                }
                if (CurrentWeapon.StateEnabled("Run"))
                {
                    CurrentWeapon.SetState("Run", false);
                }

                // fire if we have a shooter component and the mouse cursor
                // is not visible
                if (CurrentShooter != null && LockCursor)
                {
                    CurrentShooter.Fire();
                }
            }
        }

        // fire button released
        if (Input.GetMouseButtonUp(0))
        {
            // schedule to reenable 'Crouch' and / or 'Run' in half a second
            ReenableWeaponStatesIn(0.5f);

            // disregard refire delay when firing with no ammo
            if (CurrentShooter != null)
            {
                if (CurrentShooter.AmmoCount == 0)
                {
                    CurrentShooter.NextAllowedFireTime = Time.time;
                }
            }
        }
    }