How to keep gameObjects set as triggers to only trigger once, even after a scene reload?
Hi,
I am making a 2D game which uses invisible gameObjects with the "Box Collider 2D" component (with 'Is Trigger' set to true) as triggers. These trigger are mainly used to display text and whatnot. However, after creating another scene (representing another level) I came across a problem; when loading a new scene triggers will either:
a) Trigger again when entered after reloading the scene (if the object is destroyed after triggering)
or
b) Not trigger at all, even when the scene loads for the first time (if the object's SetActive is set to false after triggering)
The script I currently use for the triggers is:
public class ActivateTrigger : MonoBehaviour
{
void OnTriggerEnter2D(Collider2D player)
{
if(player.name == "PlayerBase")
{
gameObject.GetComponent<DialogueTrigger>().TriggerDialogue();
gameObject.SetActive(false);
}
}
}
However (as mentioned before) this causes triggers in the other scene to never trigger.
Is there any way to solve this? I need both triggers to only activate once then never again, even after a scene reload.
Thanks!
Your answer
Follow this Question
Related Questions
Regarding SetActive function 1 Answer
SetActive is destroying objects instead of settings them as false 0 Answers
Disable Object and Enable by Distance from Player 1 Answer
My Game Over Canvas is working in one level but not the other! 0 Answers
Unable to reactivate an object that's been deactivated. C# 4 Answers