Ejemplo n.º 1
0
    // Fixed update is called in sync with physics
    private void FixedUpdate()
    {
        if (!isLocalPlayer)
        {
            return;
        }


        if (input.BackButtonInput && !input.playerControllerInputBlocked)
        {
            input.playerControllerInputBlocked = true;
            UIEventHandler.GameMenuOpened();
        }

        // read inputs
        float x = input.LeftStickInput.x;
        float y = -input.LeftStickInput.y;

        bool aButton = input.AButtonInput;
        bool bButton = input.BButtonInput;
        bool xButton = input.XButtonInput;
        bool yButton = input.YButtonInput;

        float rightTrigger = input.RightTrigger;
        float leftTrigger  = input.LeftTrigger;

        // calculate move direction to pass to character
        if (m_Cam != null)
        {
            // calculate camera relative direction to move:
            m_CamForward = Vector3.Scale(m_Cam.forward, new Vector3(1, 0, 1)).normalized;
            m_Move       = y * m_CamForward + x * m_Cam.right;
        }
        else
        {
            // we use world-relative directions in the case of no main camera
            m_Move = y * Vector3.forward + x * Vector3.right;
        }

        // walk speed multiplier
        m_Move *= 0.5f;

        // pass all parameters to the character control script
        m_Character.ReceiveInput(m_Move, aButton, bButton, xButton, yButton, rightTrigger, leftTrigger, false, false);
        m_Jump = false;
    }