Esempio n. 1
0
    void Update()
    {
        bool swipeActive = false;
        bool moveActive = false;
        foreach (Touch t in Input.touches)
        {
            if (t.phase == TouchPhase.Began)
            {
                if ((t.position.x / Screen.width) > 0.4f)
                {
                    curSwipeFingerId = t.fingerId;
                    curSwipeTouch = t;
                    swipeStartPosition = t.position;
                    swipeStartTime = Time.time;
                    swipeActive = true;
                }
                else
                {
                    curMoveFingerId = t.fingerId;
                    curMoveTouch = t;
                    moveStartPositionX = t.position.x;
                    moveActive = true;
                }
            }

            if (t.phase == TouchPhase.Ended || t.phase == TouchPhase.Canceled)
            {
                if (t.fingerId == curSwipeFingerId)
                {
                    curSwipeFingerId = -1;
                }
                if (t.fingerId == curMoveFingerId)
                {
                    curMoveFingerId = -1;
                }
            }

            if (t.fingerId == curSwipeFingerId)
            {
                curSwipeTouch = t;
                swipeActive = true;
            }
            else if (t.fingerId == curMoveFingerId)
            {
                curMoveTouch = t;
                moveActive = true;
            }
        }

        if (swipeActive)
        {
            ProcessSwipe();
        }

        if (moveActive)
        {
            ProcessMove();
        }
        else
        {
            joystickPosition = JoystickPositions.Neutral;
        }

        if (Input.GetKeyDown("d"))
            forwardInputTimestamp = Time.time;

        if (Input.GetKeyDown("a"))
            backwardInputTimestamp = Time.time;
    }
Esempio n. 2
0
    private void ProcessMove()
    {
        UIDebug.Log("Checking movement");

        float curTouchX = curMoveTouch.position.x;
        float distance = Mathf.Abs(moveStartPositionX - curTouchX);

        if (distance > minMoveDist)
        {
            if (curTouchX > moveStartPositionX)
            {
                UIDebug.Log("MOVE RIGHT");
                joystickPosition = JoystickPositions.Right;

                if (distance > trackDistance)
                {
                    moveStartPositionX = curTouchX - trackDistance;
                }
            }
            else
            {
                UIDebug.Log("MOVE LEFT");
                joystickPosition = JoystickPositions.Left;

                if (distance > trackDistance)
                {
                    moveStartPositionX = curTouchX + trackDistance;
                }
            }
        }
        else
        {
            joystickPosition = JoystickPositions.Neutral;
        }
    }