How to stop pong paddle from moving continuously?

Hi. I’m making a android 2D pong game for practice. I used UI buttons as arrows to move the paddle. The game is working except that when i click the button, the paddle moves in that direction continuously. How to move the paddle only a small distance per UI button click?
This is my script attached to the buttons.

public class MoveRacketDown : MonoBehaviour
{
    [SerializeField]
    private GameObject racket;

    public float speed = 10f;

    void Start()
    {
        gameObject.GetComponent<Button>().onClick.AddListener(MoveRacketOnClick);
    }

    void MoveRacketOnClick()
    {
        racket.GetComponent<Rigidbody2D>().velocity = new Vector2(0,  -1) * speed;
    }
}

After some more googling and youtube videos, i found the Event Trigger component and its working fine now.

Hello, i think the problem with your code was setting velocity to that, and after that if you dont have anything that slows down or stops your pong it will just have that velocity all the time, simplest way to check if that was problem is to add .velocity=0f; after your function has been called, for example create a new

Private void stop()
{
   racket.GetComponent<Rigidbody2D>().velocity=0f;
}

and call it like Invoke(nameof(stop),0.5f)
in your MoveRackerOnClick() after you apply velocity, then you will see the results and find your best solution :slight_smile: Good Luck!