From what I see, there are 3 conditions in your OnJump method. Have you checked if all conditions have the expected value?
If one of them does not have the expected value, you could check why you get the wrong one. Maybe isAlive
is false
. We cannot know that just by reading the code.
Before the enemy reaches the wall, click the Pause button. Then zoom in on the enemy in the Scene window, so you can see its collider. Keep clicking the button that gets you to the next frame until the problem happens. Maybe you can spot an issue.
Rick’s concept is: If the periscope collider exists a collider (here: the ground collider), the enemy gets flipped.
In case it wasn’t clear: Unless you want to check every single detail in your game as suggested by Yee, which might take you a couple of hours, days or even weeks, you have to check if your current code follows the expected logic flow. By that, I don’t mean that something happens in the game window but that you get the expected values in your code. What happens in the game window is a result of your code, thus you need to check the code.