예제 #1
0
    public void Tick()
    {
        if (!_enabled)
        {
            return;
        }

        _inputRatio = Vector2.zero;
        Vector2 touchPos = Vector2.zero;
        Vector2 drag     = Vector2.zero;

        if (Input.touchCount > 0)
        {
            touchPos = Input.GetTouch(0).position;
            // [-1, 1]
            float scaledX = -1 + ((touchPos.x / screenSize.x) * 2);
            drag = touchPos - _prevTouch;

            if (drag.sqrMagnitude > dragSensitivity)
            {
                if (Mathf.Sign(drag.x) != Mathf.Sign(scaledX))
                {
                    scaledX *= -1;
                }
            }
            _inputRatio.x = scaledX;
        }

        _inputRatio.y = Mathf.Min(1, _prevRatio.y + yAcc);

        _steering.Move(_inputRatio.x, _inputRatio.y, 0.0f, 0.0f);

        _prevRatio = _inputRatio;
        _prevTouch = touchPos;
    }
예제 #2
0
    public void Tick()
    {
        if (!_enabled)
        {
            return;
        }

        _inputRatio   = Vector2.zero;
        _inputRatio.x = Input.GetAxis("Horizontal");


        _inputRatio.y = Mathf.Min(1, _prevRatio.y + yAcc);

        _steering.Move(_inputRatio.x, _inputRatio.y, 0.0f, 0.0f);
        _prevRatio = _inputRatio;
    }
예제 #3
0
    public void Tick()
    {
        if (!_enabled)
        {
            return;
        }

        Vector2 touchCurrent = Vector2.zero;

        if (Input.touchCount > 0)
        {
            switch (Input.GetTouch(0).phase)
            {
            case TouchPhase.Began:
                _touchStart = Input.GetTouch(0).position;
                break;

            case TouchPhase.Moved:
                touchCurrent = Input.GetTouch(0).position;
                break;

            case TouchPhase.Ended:
                _touchStart = Vector2.zero;
                break;
            }
        }

        _inputRatio = Vector2.zero;

        if (_touchStart.sqrMagnitude > 0 && touchCurrent.sqrMagnitude > 0)
        {
            Vector2 drag = touchCurrent - _touchStart;
            _inputRatio.x = ((drag.x / _screenSize.x) * 4);
        }


        _inputRatio.y = Mathf.Min(1, _prevRatio.y + yAcc);

        _steering.Move(_inputRatio.x, _inputRatio.y, 0.0f, 0.0f);
        _prevRatio = _inputRatio;
    }