Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown("s"))
        {
            speed = 0;
        }


        // Asigna la posicion general y da movimiento.
        GameManager.Ball = transform.position;
        transform.Translate(balldirection * speed * Time.deltaTime);
        GameManager.ballspeed = speed;


        // Hitbox superior
        if (transform.position.y < GameManager.WallLeft.y + radius + 0.6 && balldirection.y < 0)
        {
            balldirection.y = -balldirection.y;
            if (speed < 1)
            {
                speed = 0f;
            }
            else
            {
                speed -= 1f;
            }
        }
        // Hitbox inferior
        if (transform.position.y > GameManager.WallRight.y - radius - 0.5 && balldirection.y > 0)
        {
            balldirection.y = -balldirection.y;
            if (speed < 1)
            {
                speed = 0f;
            }
            else
            {
                speed -= 1f;
            }
        }

        // Detecta gol del lado izquierdo
        if (transform.position.x < GameManager.WallLeft.x + radius + 0.1 && balldirection.x < 0)
        {
            transform.position = new Vector2(0, 0);
            speed = 0;
            m2.scoreUpdate2();
            Turns.Restart();
            Debug.Log("GOAL RIGHT PLAYER WINS!");
        }
        // Detecta gol del lado derecho
        if (transform.position.x > GameManager.WallRight.x - radius - 0.1 && balldirection.x > 0)
        {
            transform.position = new Vector2(0, 0);
            speed = 0;
            m1.scoreUpdate1();
            Turns.Restart();
            Debug.Log("GOAL LEFT PLAYER WINS!");
        }


        /**
         *
         * if (transform.position.y < GameManager.WallLeft1.y + radius && balldirection.y < 0)
         * {
         *  balldirection.y = -balldirection.y;
         * }
         *
         *
         * if (transform.position.y > GameManager.WallRight1.y - radius && balldirection.y > 0)
         * {
         *  balldirection.y = -balldirection.y;
         * }
         */
    }