///////////////////////////////////////////////////////////
    // 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;
                }
            }
        }
    }
    ///////////////////////////////////////////////////////////
    // this method schedules a check in 'seconds' to reenable
    // any active states on the controller that may have been
    // temporarily disabled on the current weapon
    ///////////////////////////////////////////////////////////
    public void ReenableWeaponStatesIn(float seconds)
    {
        // cancel the timer if it's currently running, to prevent
        // problems with button spamming
        if (m_ReenableWeaponStatesTimer != null)
        {
            m_ReenableWeaponStatesTimer.Cancel();
        }

        m_ReenableWeaponStatesTimer = vp_Timer.In(seconds, delegate()
        {
            if (Controller.StateEnabled("Zoom"))
            {
                if (CurrentWeapon != null)
                {
                    CurrentWeapon.SetState("Zoom", true);
                }
                if (CurrentShooter != null)
                {
                    CurrentShooter.SetState("Zoom", true);
                }
                return;                 // don't reenable 'Crouch' or 'Run' on the weapon while zooming
            }
            if (Controller.StateEnabled("Crouch"))
            {
                if (CurrentWeapon != null)
                {
                    CurrentWeapon.SetState("Crouch", true);
                }
                if (CurrentShooter != null)
                {
                    CurrentShooter.SetState("Crouch", true);
                }
            }
            if (Controller.StateEnabled("Run"))
            {
                if (CurrentWeapon != null)
                {
                    CurrentWeapon.SetState("Run", true);
                }
                if (CurrentShooter != null)
                {
                    CurrentShooter.SetState("Run", true);
                }
            }
        });
    }
示例#3
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;
                }
            }
        }
    }
    ///////////////////////////////////////////////////////////
    // sets a state on the controller, camera, current weapon
    // and current shooter. NOTE: SetState does not update
    // currently disabled weapons or shooters
    ///////////////////////////////////////////////////////////
    public void SetState(string state, bool isEnabled)
    {
        if (Controller != null)
        {
            Controller.SetState(state, isEnabled);
        }

        if (Camera != null)
        {
            Camera.SetState(state, isEnabled);
            if (CurrentWeapon != null)
            {
                CurrentWeapon.SetState(state, isEnabled);
            }
            if (CurrentShooter != null)
            {
                CurrentShooter.SetState(state, isEnabled);
            }
        }
    }