コード例 #1
0
 protected virtual void FixedUpdate()
 {
     if (MoveMechanism.UsesRigidbody())
     {
         GameManager.PlayerMoving(player, move);
         player.Move(move);
     }
 }
コード例 #2
0
        protected virtual void Update()
        {
            if (useTouchControl)
            {
                if (Input.touchCount > 0)
                {
                    Touch touchZero = Input.GetTouch(0);
                    switch (touchZero.phase)
                    {
                    case TouchPhase.Began:
                        touchReleased   = false;
                        touchBeginPoint = touchZero.position;
                        break;

                    case TouchPhase.Moved:
                        touchDelta = (touchZero.position - touchBeginPoint) / (float)touchSensitivity;
                        hInput     = touchDelta.x;
                        vInput     = touchDelta.y;
                        break;

                    case TouchPhase.Ended:
                        touchReleased = true;
                        break;

                    default:
                        break;
                    }
                    Debug.DrawLine(Camera.main.ScreenToWorldPoint(touchBeginPoint), Camera.main.ScreenToWorldPoint(touchZero.position));
                }

                if (touchReleased && touchDelta.magnitude > 0)
                {
                    touchDelta = Vector2.Lerp(touchDelta, Vector2.zero, Time.deltaTime * 5.0f);

                    if (touchDelta.magnitude < 0.05f)
                    {
                        touchDelta = Vector2.zero;
                    }

                    hInput = touchDelta.x;
                    vInput = touchDelta.y;
                }
            }
            else
            {
                hInput           = Input.GetAxis("Horizontal");
                vInput           = Input.GetAxis("Vertical");
                player.Attacking = Input.GetKey(KeyCode.LeftShift);
            }

            if (Mathf.Approximately(hInput, 0) && Mathf.Approximately(vInput, 0))
            {
                if (!didWeCallPlayerStopped)
                {
                    GameManager.PlayerStopped(player);
                    didWeCallPlayerStopped = true;
                }
            }
            else
            {
                didWeCallPlayerStopped = false;
            }

            if (mainCamera != null)  // calculate camera relative direction
            {
                camForward = Vector3.Scale(mainCamera.forward, new Vector3(1, 0, 1)).normalized;
                move       = ((vInput * camForward + hInput * mainCamera.right) * speed).ClampMagnitude(speed);
            }
            else  // world-relative directions in the case of no camera
            {
                move = ((vInput * Vector3.forward + hInput * Vector3.right) * speed).ClampMagnitude(speed);
            }

            if (MoveMechanism.UsesRigidbody())
            {
                return;
            }
            GameManager.PlayerMoving(player, move);
            player.Move(move);
        }