Example #1
0
    public void OnFingerSet(Lean.LeanFinger finger)
    {
        // Is this the current finger?
        if (finger == swipingFinger)
        {
            // The scaled delta position magnitude required to register a swipe
            var swipeThreshold = Lean.LeanTouch.Instance.SwipeThreshold;

            // The amount of seconds we consider valid for a swipe
            var tapThreshold = Lean.LeanTouch.Instance.TapThreshold;

            // Get the scaled delta position between now, and 'swipeThreshold' seconds ago
            var recentDelta = finger.GetScaledSnapshotDelta(tapThreshold);

            // Has the finger recently swiped?
            if (recentDelta.magnitude > swipeThreshold)
            {
                // Get the rigidbody component
                var rigidbody = GetComponent <Rigidbody>();

                // Add force to the rigidbody based on the swipe force
                rigidbody.AddForce(recentDelta.normalized * ImpulseForce, ForceMode.Impulse);

                // Unset the finger so we don't continually add forces to it
                swipingFinger = null;
            }
        }
    }
Example #2
0
    public void OnFingerSet(Lean.LeanFinger finger)
    {
        // Is this the current finger?
        if (finger == swipingFinger)
        {
            // The scaled delta position magnitude required to register a swipe
            var swipeThreshold = Lean.LeanTouch.Instance.SwipeThreshold;

            // The amount of seconds we consider valid for a swipe
            var tapThreshold = Lean.LeanTouch.Instance.TapThreshold;

            // Get the scaled delta position between now, and 'swipeThreshold' seconds ago
            var recentDelta = finger.GetScaledSnapshotDelta(tapThreshold);

            // Has the finger recently swiped?
            if (recentDelta.magnitude > swipeThreshold)
            {
                // Store the swipe delta in a temp variable
                var swipe = finger.SwipeDelta;
                var left  = new Vector2(-1.0f, 0.0f);
                var right = new Vector2(1.0f, 0.0f);
                var down  = new Vector2(0.0f, -1.0f);
                var up    = new Vector2(0.0f, 1.0f);

                if (SwipedInThisDirection(swipe, left + up) == true)
                {
                    //InfoText.text = "You swiped left and up!";
                    GridData.gridManager.TryMovePlayer(MoveDirection.LeftUp);
                }

                else if (SwipedInThisDirection(swipe, left + down) == true)
                {
                    //InfoText.text = "You swiped left and down!";
                    GridData.gridManager.TryMovePlayer(MoveDirection.LeftDown);
                }

                else if (SwipedInThisDirection(swipe, right + up) == true)
                {
                    //InfoText.text = "You swiped right and up!";
                    GridData.gridManager.TryMovePlayer(MoveDirection.RightUp);
                }

                else if (SwipedInThisDirection(swipe, right + down) == true)
                {
                    //InfoText.text = "You swiped right and down!";
                    GridData.gridManager.TryMovePlayer(MoveDirection.RightDown);
                }

                // Unset the finger so we don't continually add forces to it
                swipingFinger = null;
            }
        }
    }