- Home /
The question is answered, right answer was accepted
Using OnTriggerEnter2D/OnTriggerExit2D with Time.timeScale set to 0
Is it possible to use OnTriggerEnter2D and OnTriggerExit2D if I have set Time.timeScale to 0?
I am creating a micromanagement game where the game pauses when you are building things. The problem arose when I tried to prevent building a city in the middle of the ocean. The game detects oceans by using a box collider 2D with isTrigger set to true. So, I have a variable called canBuild that is true if all requirements for building the city are met, and is false if the player cannot build. To check if the city is in the ocean when building, I use OnTriggerEnter2D, check if the tag of the collider's gameObject is "Ocean", and if so set canBuild to false. I do the same thing with OnTriggerExit2D for when the city is on land to set canBuild to true. The problem is, when Time.timeScale is 0, I found that the physics engine is not running, and therefore is not calling these functions.
Answer by Nobozarb · Dec 26, 2017 at 07:08 PM
I have figured out what to do. I used Physics2D.Simulate() to detect collisions and Collider2D.IsTouchingLayers().