[BUG] Ball launches every mouse click not just the first time

Not sure if I missed where this was accounted for in the sample code. What I did on my end to stop it was to add the following…
inside the Ball class…
private bool isPlaying = false;
then in Update below the hasStarted = true; line I added
if (!isPlaying) {
this.rigidbody2D.velocity = new Vector2 (2f, 10f);
}
isPlaying = true;

This solved it for me but I am unsure if that is A) the best way and B) if this was addressed by you and I missed it.

Hansmo

My guess is your Input.GetMouseButton is not in your if (!hasStarted) statement. Like the ball transform, the get mouse should not run if the game has started.

I placed the mousepress code inside the (!hasStarted) if statement and that fixed the issue for me.

if (!hasStarted){
code to lock ball to paddle

    if(mouse is clicked){
        launch ball
    }
}

Once the game starts the code to launch the ball can’t be executed.

Thanks for the tip

Privacy & Terms