void FixedUpdate()
 {
     if (!IsVisibleOn3dCamera(head, gameObject.GetComponent <Camera>()))
     {
         //transform.position = head.transform.position - offset;
         targetPosition     = head.transform.position + offset;
         transform.position = Vector3.Lerp(transform.position, targetPosition, smooth * Time.deltaTime);
         mainCamera.Move();
     }
 }
Пример #2
0
    // Update is called once per frame
    void Update()
    {
        float horiz = KeyInputHold(KeyCode.D, KeyCode.A);
        float vert  = KeyInputHold(KeyCode.W, KeyCode.S);

#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
        if (!playerIndexSet || !prevState.IsConnected)
        {
            for (int i = 0; i < 4; ++i)
            {
                PlayerIndex  testPlayerIndex = (PlayerIndex)i;
                GamePadState testState       = GamePad.GetState(testPlayerIndex);
                if (testState.IsConnected)
                {
                    Debug.Log(string.Format("GamePad found {0}", testPlayerIndex));
                    playerIndex    = testPlayerIndex;
                    playerIndexSet = true;
                }
            }
        }

        prevState = state;
        state     = GamePad.GetState(playerIndex);

        Vector2 leftStick  = ApplyStickDeadzone(state.ThumbSticks.Left);
        Vector2 rightStick = ApplyStickDeadzone(state.ThumbSticks.Right);

        if (isRunningAnalogue)
        {
            if (leftStickCheckTimer < leftStickCheckTime)
            {
                leftStickCheckTimer += Time.deltaTime;
            }
            else
            {
                if (!leftStickCheck)
                {
                    isRunningAnalogue = false;
                }

                leftStickCheck      = false;
                leftStickCheckTimer = 0;
            }
        }

        // If left stick movement is being picked up
        if (leftStick != Vector2.zero)
        {
            // Clicking the left stick toggles running
            if (OnXInputButtonDown(prevState.Buttons.LeftStick, state.Buttons.LeftStick))
            {
                isRunningAnalogue = !isRunningAnalogue;
            }

            bool runCancel = false;
            playerController.MoveAnalogue(leftStick.x, leftStick.y, isRunningAnalogue, ref runCancel);

            if (runCancel)
            {
                isRunningAnalogue   = false;
                leftStickCheck      = false;
                leftStickCheckTimer = 0;
            }
            leftStickCheck = true;
        }
        else
        {
            playerController.MoveKeyboard(horiz, vert, Input.GetKey(KeyCode.LeftShift), Input.GetKey(KeyCode.LeftControl));
        }

        if (rightStick != Vector2.zero)
        {
            playerCam.Move(rightStick.x, rightStick.y);
        }
        else
        {
            playerCam.Move(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));
        }

        float horizCam = state.ThumbSticks.Right.X != 0 ? state.ThumbSticks.Right.X * rightStickSensitivity : Input.GetAxisRaw("Mouse X");
        float vertCam  = state.ThumbSticks.Right.Y != 0 ? state.ThumbSticks.Right.Y * rightStickSensitivity : Input.GetAxisRaw("Mouse Y");
        //playerCam.SetAxes(horizCam, vertCam);

        bool aimInput = state.Triggers.Left > 0.1f || Input.GetMouseButton(1);
        bool jump     = prevState.Buttons.A == ButtonState.Released && state.Buttons.A == ButtonState.Pressed || Input.GetKeyDown(KeyCode.Space);
#else
        playerController.Move(horiz, vert);

        float horizCam = Input.GetAxisRaw("Mouse X");
        float vertCam  = Input.GetAxisRaw("Mouse Y");
        bool  aimInput = Input.GetMouseButton(1);
        bool  jump     = Input.GetKeyDown(KeyCode.Space);
#endif
    }