Hi everyone!
I’m making a 4 player coop game and I’m running into problems with trigger based switches, where more than one player can activate the switch at a time. I’ve tried lots of different workarounds include using bools that coincide with a player’s ID string but I just can’t seem to get a grasp on the logic. I need a way to disable a trigger (or keep other players from using it) while one player is inside the trigger but I’m having a hard time. I’ve tried a triggerEnabled bool which is made true when the player presses a button while in the trigger and then used in an if statement that is supposed to return if this bool is true. In my mind that should effectively render the trigger useless to other players while someone is already inside it but its not working. Example code:
private bool triggerEnabled;
void OnTriggerEnter2D (Collider2D col)
{
if(col.tag == "Player" && !triggerEnabled)
{
triggerEnabled = true;
//Do Some Other Stuff
}
if(col.tag == "Player" && triggerEnabled)
{
return;
}
}
I’d be very grateful if anyone could tell me why this logic is flawed and/or offer a solution! I appreciate it!