Пример #1
0
    void Update()
    {
        if (collider && !colliderPlayer.IsTouchingLayers(layerCaixas) && !EmMovimentoPulo)
        {
            GameControl.instance.Morreu();
            anim.SetTrigger("Morreu");
            Morreu = true;
        }

        float posicaoX = transform.localPosition.x;

        if (!Morreu)
        {
            if (!EmMovimentoPulo)
            {
                //Para esquerda - Teclado
                if (Input.GetKeyDown(KeyCode.LeftArrow))
                {
                    anim.SetTrigger("Jump");

                    if (posicaoX == -constanteLateral)
                    {
                        StartCoroutine(ParabolaPuloEsquerdaLimite(transform.localPosition.x));
                    }
                    else
                    {
                        StartCoroutine(ParabolaPuloEsquerda(transform.localPosition.x));
                    }
                }

                //Para direita - Teclado
                if (Input.GetKeyDown(KeyCode.RightArrow))
                {
                    anim.SetTrigger("Jump");

                    if (posicaoX == constanteLateral)
                    {
                        StartCoroutine(ParabolaPuloDireitaLimite(transform.localPosition.x));
                    }
                    else
                    {
                        StartCoroutine(ParabolaPuloDireita(transform.localPosition.x));
                    }
                }

                if (Input.touchCount > 0)
                {
                    Touch t = Input.GetTouch(0);

                    if (t.phase == TouchPhase.Began)
                    {
                        firstPressPos = t.position;
                    }

                    if (t.phase == TouchPhase.Ended)
                    {
                        Vector2 secondPressPos = t.position;

                        //Para esquerda - Swipe
                        if ((secondPressPos.x < firstPressPos.x) && (Mathf.Abs(firstPressPos.x) - Mathf.Abs(secondPressPos.x) > 10f))
                        {
                            anim.SetTrigger("Jump");

                            if (posicaoX == -constanteLateral)
                            {
                                StartCoroutine(ParabolaPuloEsquerdaLimite(transform.localPosition.x));
                            }
                            else
                            {
                                StartCoroutine(ParabolaPuloEsquerda(transform.localPosition.x));
                            }
                        }

                        //Para direita - Swipe
                        if ((secondPressPos.x > firstPressPos.x) && (Mathf.Abs(secondPressPos.x) - Mathf.Abs(firstPressPos.x) > 10f))
                        {
                            anim.SetTrigger("Jump");

                            if (posicaoX == constanteLateral)
                            {
                                StartCoroutine(ParabolaPuloDireitaLimite(transform.localPosition.x));
                            }
                            else
                            {
                                StartCoroutine(ParabolaPuloDireita(transform.localPosition.x));
                            }
                        }
                    }
                }
            }
        }
        else
        {
            if (Input.GetKeyDown(KeyCode.Space))
            {
                GameControl.instance.NovoJogo();
            }

            if (Input.GetKeyDown(KeyCode.L))
            {
                SaveControl.ResetaIAJogo();
            }

            if (Input.touchCount > 0)
            {
                Touch t = Input.GetTouch(0);

                if (t.phase == TouchPhase.Began)
                {
                    if (EventSystem.current.currentSelectedGameObject.name == "resetIaButton")
                    {
                        botaoReiniciarIA = true;
                    }

                    if (EventSystem.current.currentSelectedGameObject.name == "gameOverButton")
                    {
                        botaoReiniciarJogo = true;
                    }
                }

                if (t.phase == TouchPhase.Ended)
                {
                    if (botaoReiniciarIA)
                    {
                        botaoReiniciarIA = false;
                        SaveControl.ResetaIAJogo();
                    }

                    if (botaoReiniciarJogo)
                    {
                        botaoReiniciarJogo = false;
                        GameControl.instance.NovoJogo();
                    }
                }
            }
        }
    }