예제 #1
0
 public void SetInputType(int i)
 {
     if (i < 3)
     {
         inputEnum e = (inputEnum)i;
         inputType = e;
     }
     else
     {
         Debug.LogError("You are trying to manually change Input Type on " + this.name + ". Integer value must be 0 - 2.");
     }
 }
예제 #2
0
    public void Swipe()
    {
        if (Input.GetMouseButtonDown(0))
        {
            //save began touch 2d point
            firstPressPos = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
        }

        if (Input.GetMouseButtonUp(0))
        {
            //save ended touch 2d point
            secondPressPos = new Vector2(Input.mousePosition.x, Input.mousePosition.y);

            firstPressPos  = Camera.main.ScreenToWorldPoint(firstPressPos);
            secondPressPos = Camera.main.ScreenToWorldPoint(secondPressPos);

            //create vector from the two points
            currentSwipe = new Vector2(secondPressPos.x - firstPressPos.x, secondPressPos.y - firstPressPos.y);
//            Debug.Log(currentSwipe);
//            Debug.Log(swipeTreshold);
            if (currentSwipe.x > -swipeTreshold && currentSwipe.x < swipeTreshold && currentSwipe.y > -swipeTreshold && currentSwipe.y < swipeTreshold)
            {
//                Debug.Log("Clicked");
                inputState = inputEnum.Clicked;
            }
            else
            {
                //normalize the 2d vector
                currentSwipe.Normalize();

                //swipe upwards
                if (currentSwipe.y > 0 && currentSwipe.x > -0.5f && currentSwipe.x < 0.5f)
                {
//                    Debug.Log("up");
                    inputState = inputEnum.SwipedUp;
                }

                //swipe down
                if (currentSwipe.y < 0 && currentSwipe.x > -0.5f && currentSwipe.x < 0.5f)
                {
//                    Debug.Log("down");


                    inputState = inputEnum.SwipedDown;
                }

                //swipe left
                if (currentSwipe.x < 0 && currentSwipe.y > -0.5f && currentSwipe.y < 0.5f)
                {
//                    Debug.Log("left");

                    inputState = inputEnum.SwipedLeft;
                }

                //swipe right
                if (currentSwipe.x > 0 && currentSwipe.y > -0.5f && currentSwipe.y < 0.5f)
                {
//                    Debug.Log("right");

                    inputState = inputEnum.SwipedRight;
                }
            }
        }
    }