AnythingTrigger
is a C# script for Unity that defines an event trigger for colliders that can be configured in the editor inspector without code to trigger any type of action. The script provides several customizable options, including the tag that the collider must have to trigger the event, whether the game object should be destroyed when the trigger activates, and how long to wait before destroying the game object. The script also provides an option to only trigger the event once.
To use AnythingTrigger
in your Unity project, simply copy the AnythingTrigger.cs
script into your project's Assets
folder.
To use AnythingTrigger
, attach the script to a game object that has a collider attached. The script provides several options that can be customized in the Unity Inspector:
- Seeking Tag: The tag that the collider must have to trigger the event.
- Destroy On Trigger: Whether the game object should be destroyed when the trigger activates.
- Time To Destroy: How long to wait before destroying the game object.
- Only Trigger Once: Whether the trigger should only activate once.
- On Trigger Enter Event: The UnityEvent that gets triggered when the collider with the seeking tag enters the area.
When the trigger is activated, the OnTriggerEnter
function is called. If Only Trigger Once
is true and the trigger has already activated, the function exits without doing anything. If the collider has the correct tag, the OnTriggerEnterEvent
is triggered, and the Destroy On Trigger
and Time To Destroy
options are taken into consideration. Finally, if Only Trigger Once
is true, the trigger is set to only activate once.
Here's an example of how to use AnythingTrigger
:
- Create a new game object in your Unity scene and add a collider to it.
- Attach the
AnythingTrigger
script to the game object. - In the Unity Inspector, set the
Seeking Tag
to the tag that you want to trigger the event. - (Optional) Set the
Time To Destroy
if you want the game object to be destroyed after the trigger activates. - (Optional) Check the
Only Trigger Once
box if you only want the trigger to activate once. - Add any functions that you want to trigger to the
On Trigger Enter Event
in the Unity Inspector. - Save your scene and run your game.
AnythingTrigger
is released under the MIT license. See the LICENSE file for more details.
AnythingTrigger
was created by Robert Rumney. Feel free to contribute to this project by submitting pull requests or issues.