Exemplo n.º 1
0
    private void OnSwipe(LeanFinger finger)
    {
        if (ball != null)
        {
            return;
        }
        var ballPos = finger.GetStartWorldPosition(10);

        ball = Instantiate(BallPrefab, new Vector2(ballPos.x, StartYPos), Quaternion.identity);
        ball.GetComponent <BallController>().Launch(finger.SwipeScaledDelta);
    }
Exemplo n.º 2
0
    public void OnTouchUp(LeanFinger finger)
    {
        // print( gameObject);
        Vector2 fingerWorldPosition = finger.GetStartWorldPosition(10);


        Collider2D collider = Physics2D.OverlapBox(fingerWorldPosition, new Vector2(0.1f, 0.1f), 0);

        if (collider == null)
        {
            return;
        }



        if (GetComponent <Collider2D>().bounds.Contains(fingerWorldPosition) == false)
        {
            return;
        }


        Vector2 launchDirection = (finger.ScreenPosition - finger.StartScreenPosition);

        if (Mathf.Abs(launchDirection.x) > Mathf.Abs(launchDirection.y))//aca entra si horizontal es mas grande que vertical
        {
            if (launchDirection.x < 0)
            {
                launchDirection.x = -1;
            }
            else
            {
                launchDirection.x = 1;
            }
            launchDirection.y = 0;
        }
        else //aca entra si vertical es mas grande que horizontal
        {
            if (launchDirection.y < 0)
            {
                launchDirection.y = -1;
            }
            else
            {
                launchDirection.y = 1;
            }
            launchDirection.x = 0;
        }

        //cambie impulse a velocity porque kinematic mas arcade
        GetComponent <Rigidbody2D>().velocity = launchDirection * launchPower;
    }
Exemplo n.º 3
0
    void Swiped(LeanFinger finger)
    {
        if (DateTime.Now < signDoneChangingAfter)
        {
            Debug.Log("still changing");
            return;
        }
        Debug.Log("--------------------------");
        Debug.Log("SWIPED");

        var swipeStart = finger.GetStartWorldPosition(0);
        var swipeEnd   = finger.GetLastWorldPosition(0);
        var heading    = swipeEnd - swipeStart;
        var distance   = heading.magnitude;
        var direction  = heading / distance;

        RaycastHit2D[] hits = Physics2D.RaycastAll(swipeStart, direction);

        foreach (var hit in hits)
        {
            if (hit.collider == signBoxCollider)
            {
                signDoneChangingAfter = DateTime.Now.AddSeconds(1);

                isSignBack = !isSignBack;
                Debug.Log(isSignBack);
                if (isSignBack)
                {
                    signSpriteRender.sprite = signBack;
                }
                else
                {
                    signSpriteRender.sprite = signFront;
                }
                Debug.Log("hit sign");
            }
            else
            {
                Debug.Log("No collisiion!");
            }
        }
    }
Exemplo n.º 4
0
 void OnFingerDown(LeanFinger finger)
 {
     Debug.Log("finger " + finger.Index + " " + finger.GetStartWorldPosition(0));
 }
Exemplo n.º 5
0
        private void OnLeftSwipe(LeanFinger finger)
        {
            Utils.LogConditional(nameof(InputManager) + " left swipe");

            Swiped?.Invoke(SwipeDirection.Left, finger.GetStartWorldPosition(-10));
        }