OnTriggerExit not triggering when disabling an object,OnTriggerEnter and OnTriggerExit working inconsistently when disabling an object
Long story short: 2 players, one takes damage in the light, one in the darkness, there's lightswitches to turn lights on and off. The light works with a capsule collider on the default spotlights and I use OnTriggerEnter and OnTriggerExit to set a boolean for each player to determine when they should take damage (applied in FixedUpdate).
The tricky thing is the lightswitches. Let's say LightPlayer is in the location of a light source. DarkPlayer flips a switch and the light goes off, disabling the GameObject and thus the light and the collider attached to it. OnTriggerExit doesn't trigger and the player doesn't start taking damage. However, if the LightPlayer walks into the area while taking damage and DarkPlayer turns the lights on OnTriggerEnter goes off and LightPlayer stops taking damage.
Is there an easy fix to force OnTriggerExit when disabling an object?,I have this project I'm working on and the concept is simple: 2 players working together to solve puzzles, one takes damage in the darkness and the other in the light. So I made light switches and added a collider to all light sources. I use OnTriggerEnter and OnTriggerExit to assign a boolean to determine whether the players should take damage in the fixedUpdate.
The thing is, when a player is in range of a lightsource, and the other player flips the switch, OnTriggerEnter gets triggered when it should but OnTriggerExit does not. Is there an easy fix to this?
Answer by Chrizie · May 16, 2017 at 02:18 PM
For those interested, I haven't found a solution so now I just use OnTriggerStay to set a boolean to true and set that boolean to false every frame using FixedUpdate. It's not the fix I wanted but it's the fix I'm using because there's no answer after almost 2 weeks.