private void Update()
    {
        ControladorCamera controladorCamera = ControladorCamera.GetInstancia();
        Vector2           position          = this.transform.position;

        position.y -= (GetAltura() / 2f);
        // Esta fora da tela
        if (!estaDentroTela)
        {
            if (controladorCamera.EstaDentroTelaVertical(position))
            {
                this.estaDentroTela = true;
            }
        }
        else
        {
            // Caso esteja dentro da tela
            position    = this.transform.position;
            position.y += (GetAltura() / 2f);
            if (controladorCamera.EstaForaTelaBaixo(position))
            {
                this.estaDentroTela = false;
                this.controladorBackground.SaiuTela(this);
            }
        }
    }
Пример #2
0
    void move()
    {
        bool moverCima = Input.GetKey(KeyCode.W);
        bool moverBaixo = Input.GetKey(KeyCode.S);
        bool moverEsquerda = Input.GetKey(KeyCode.A);
        bool moverDireita = Input.GetKey(KeyCode.D);
        int  x, y;

        x = moverDireita ? 1 : moverEsquerda ? -1 : 0;
        y = moverCima ? 1 : moverBaixo ? -1 : 0;

        Vector2 posicao = new Vector2(x * this.velocity, y * this.velocity);

        this.rb.velocity = posicao;

        //Testa se o jador saiu da tela
        ControladorCamera controladorCamera = ControladorCamera.GetInstancia();

        posicao    = this.transform.position;
        posicao.y -= (GetAltura() / 2);
        //Verifica se saiu pela parte de baixo
        if (controladorCamera.EstaForaTelaBaixo(posicao))
        {
            Debug.Log("entrou");
            Vector2 posicaoMundo = controladorCamera.GetPosicaoMundo(Vector2.zero);
            posicao   = this.transform.position;
            posicao.y = (posicaoMundo.y + (GetAltura() / 2));
            this.transform.position = posicao;
        }
    }