Ball launches when i push play

After i added the following, the ball just falls off the paddle right when i push play in unity.
It also just falls off when i cycle through game over, and start new game screens.

void Update()
{
if (!hasStarted)
{
LockBallToPaddle();
LaunchOnMouseClick();
}
}

private void LaunchOnMouseClick()
{
    if (Input.GetMouseButtonDown(0))
    {
        hasStarted = true;
        GetComponent<Rigidbody2D>().velocity = new Vector2(2f, 15f);
    }
}

If the ball is just rolling off the paddle the problem most likely lies with the LockBallToPaddle method and not the one you are showing here. With what is provided all I can suggest is for you to double check that method and to double check the hasStarted bool to make sure it isn’t defaulted to true.

This topic was automatically closed after 43 hours. New replies are no longer allowed.

Privacy & Terms