Exemple #1
0
    private Touch touchDash(Touch touch, TouchClazz touchInz)
    {
        try
        {
            Vector2 vectorMovimiento = touch.position - touchInz.getPosition();
            Vector3 normalizado      = vectorMovimiento.normalized;

            RaycastHit2D hit = Physics2D.Linecast(transform.position, transform.position + normalizado * 5, blockingLayer);
            if (hit)
            {
                // Vector3 posicionFinal = new Vector3(hit.point.x, hit.point.y, 0);
                // vectorMovimiento = posicionFinal - transform.position;
                //  normalizado = vectorMovimiento.normalized;
            }
            Vector3 vectorIniFinal = transform.position + normalizado * 5;

            DrawDashLine(transform.position, vectorIniFinal, 0.2f);
            this.gameObject.transform.Translate(normalizado * 6);

            playerController.MoveHorizontally(0);
            playerController.SetVerticalForce(0);
            // playerController.AddForce(normalizado.x * 10, normalizado.y * 10);
            if (gameController.isTimeSlowedDown)
            {
                // gameController.SwapTimeScale();
            }
        }
        catch (Exception e)
        {
            infoError.text = "Error" + e.Message;
        }

        return(touch);
    }
Exemple #2
0
    private void DrawTouchLine(int touchId, Vector3 end)
    {
        try
        {
            Color color = Color.blue;

            TouchClazz touchIntz = touchIdTopressedPosition[touchId];
            //uiTouch.GetComponentInChildren<GameObject>();

            if (!touchIntz.getTouchLine())
            {
                GameObject touchLine = new GameObject();
                touchLine.transform.position = touchIntz.getPosition();
                touchLine.AddComponent <LineRenderer>();
                touchLine.transform.SetParent(touchIntz.getUiTouch().transform, false);
                touchIntz.setTouchLine(touchLine);

                LineRenderer lr = touchLine.GetComponent <LineRenderer>();
                lr.startColor = color;

                lr.startWidth = 0.1f;
                lr.endWidth   = 0.1f;
                lr.SetPosition(0, touchIntz.getPosition());
                lr.SetPosition(1, end);
            }
            else
            {
                GameObject   touchLine = touchIntz.getTouchLine();
                LineRenderer lr        = touchLine.GetComponent <LineRenderer>();
                lr.SetPosition(1, end);
            }

            //  GameObject.Destroy(myLine, duration);
        }
        catch (Exception e)
        {
            infoError.text = "Error" + e.Message + e.StackTrace;
        }
    }
Exemple #3
0
    void HandleTouchScreen()
    {
        normalizedHorizontalSpeed = 0;

        infoTime.text = "isTimeSlow: " + gameController.isTimeSlowedDown;

        for (int i = 0; i < Input.touchCount; i++)
        {
            Touch touch = Input.GetTouch(i);

            // began
            if (touch.phase == TouchPhase.Began)
            {
                TouchClazz touchInz = new TouchClazz(touch.fingerId, EnumTouch.none, touch.position);



                PointerEventData pointer = new PointerEventData(EventSystem.current);
                pointer.position = touch.position;

                List <RaycastResult> raycastResults = new List <RaycastResult>();
                EventSystem.current.RaycastAll(pointer, raycastResults);

                if (raycastResults.Count > 0)
                {
                    GameObject result = raycastResults[0].gameObject;
                    if (result == padMove.gameObject)
                    {
                        touchInz.setMove(EnumTouch.horizontalMove);
                    }
                    else if (result == padJump.gameObject)
                    {
                        if (playerController.CanJump)
                        {
                            touchInz.setMove(EnumTouch.verticalMove);
                            playerController.Jump();
                        }
                    }
                    else if (result == padAtack.gameObject)
                    {
                        touchInz.setMove(EnumTouch.oneTouch);
                        animator.SetTrigger("triggerFrontAttack");
                    }
                }

                touchIdTopressedPosition.Add(touch.fingerId, touchInz);
                touchIdTopressedPosition[touch.fingerId].setUiTouch(DrawCircle(touch.position));
            }

            //middle

            if (touchIdTopressedPosition.ContainsKey(touch.fingerId))
            {
                TouchClazz touchInz = touchIdTopressedPosition[touch.fingerId];

                Vector2 mouseMovement = touch.position - touchInz.getPosition();

                DrawTouchLine(touch.fingerId, touch.position);

                if (!gameController.isTimeSlowedDown)
                {
                    if (touchInz.isValid(EnumTouch.dashTouch))
                    {
                        touchInz.setMove(EnumTouch.dashTouch);
                    }
                    if (touchInz.isValid(EnumTouch.horizontalMove))
                    {
                        if (Mathf.Abs(mouseMovement.y) < Mathf.Abs(mouseMovement.x) && Mathf.Abs(mouseMovement.x) > offsetTouch)
                        {
                            // entra aqui si es un movimiento en x

                            horizontalMove(touchInz, mouseMovement);
                        }
                        else if (Mathf.Abs(mouseMovement.y) < Mathf.Abs(mouseMovement.x) && Mathf.Abs(mouseMovement.x) < offsetTouch)
                        {
                            // entra aqui si es un movimiento en x

                            playerController.MoveHorizontally(0);
                        }
                    }


                    else if (Mathf.Abs(mouseMovement.y) > Mathf.Abs(mouseMovement.x) && Mathf.Abs(mouseMovement.y) > offsetTouch &&
                             touchInz.isValid(EnumTouch.verticalMove))
                    {
                        //entra aqui si el movimiento es en y
                        verticalMove(touch, touchInz, mouseMovement);
                    }
                    else if (Mathf.Abs(mouseMovement.y) < offsetTouch && Mathf.Abs(mouseMovement.x) < offsetTouch &&
                             touchInz.isValid(EnumTouch.none))
                    {
                        touchProlongado(touchInz);
                    }
                }
                else
                {
                    // estamos en slowIime
                    if (touchInz.isValid(EnumTouch.dashTouch))
                    {
                        infoEnded.text = "setea" + EnumTouch.dashTouch;
                        touchInz.setMove(EnumTouch.dashTouch);
                    }
                }

                if (touch.phase == TouchPhase.Ended)
                {
                    infoEnded.text = touchInz.getMove().ToString();


                    if (touchInz.getMove().Equals(EnumTouch.dashTouch))
                    {
                        touchDash(touch, touchInz);
                    }

                    /*
                     * else if (Mathf.Abs(mouseMovement.y) < offsetTouch && Mathf.Abs(mouseMovement.x) < offsetTouch &&
                     *   !touchInz.getMove().Equals(EnumTouch.timeTouch))
                     * {
                     *  animator.SetTrigger("triggerFrontAttack");
                     * }
                     */
                    else if (touchInz.getMove().Equals(EnumTouch.timeTouch) && gameController.isTimeSlowedDown)
                    {
                        gameController.SwapTimeScale();
                    }
                    else if (touchInz.getMove().Equals(EnumTouch.horizontalMove))
                    {
                        playerController.MoveHorizontally(0);
                    }
                    removeTouch(touch.fingerId);
                }
            }
        }
        if (Input.touchCount <= 0)
        {
            playerController.MoveHorizontally(0);
        }

        if (!playerController.CanJumpAttack)
        {
            animator.SetBool("boolJumpAttack", false);
        }
    }