How do I check if a particular trigger has been triggered before?

While creating a 2D platformer, the idea of incorporating respawn points with unique abilities crossed my mind. However, I aimed to ensure that the feature was bug-free and prevented players from exploiting it by repeatedly triggering the points to acquire abilities indefinitely.

Hi Malay,

The computer cannot remember anything. If you want to check if something has happened before, you have to assign that information to a variable. Then you can read the value of the variable at runtime to figure out if something has happened before according to the logic of your code.


See also:

1 Like

There is a trick you could use if you want a trigger to only be used once; Destroy the trigger once it’s been used.

1 Like

Delaying the destruction of the object may not be effective as the player can repeatedly enter during that time and reset the timer. Additionally, the object is meant to serve as a checkpoint and not be destroyed. However, an immediate destruction can be a solution if needed.

I was able to fix the issue by following a tutorial on YouTube. I learned that I needed to create a new script specifically for the checkpoint and assign a public boolean to track whether it had been activated or not. This information was then used in my PlayerMovement script to disable the player’s special ability.

Good job! :slight_smile:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms