How can you make OnTriggerEnter2D register multiple times?

Hi, I’m SpongeBob135, a complete Unity beginner, and I would like to know how you can make OnTriggerEnter2D register multiple times for the duration that something collides with the trigger. Right Now, it only registers once. Here is the code, if necessary:

    public GameObject player;
    public Rigidbody2D rb;
    public ScoreManager sc;

    public float jumpVelocity;

    void OnTriggerEnter2D () {
        player.GetComponent<Rigidbody2D>().AddForce(new Vector2(0, 1 * jumpVelocity));
        sc.jumpup = true;
    }
}

You can’t, because it’s doing what it’s designed to do. There is a method called “OnTriggerStay2D” (I think that names right), and that gets called every physics update that you’re within the trigger. :slight_smile:
If you want to do your own version of this, at a slower rate , then you could begin a coroutine when you enter the trigger and have it continue at the frequency you want, until you exit the trigger and stop the coroutine.

Hope that helps :slight_smile:

2 Likes

It did. Thanks again! :smile:

Cool. You’re welcome :slight_smile: