I have simple situation. When user push the mouse button my object moves. If this object collides with something player loose the game, when it doesn’t player win the game.
How can I check in the simplest way that player win or loose?
I try to use simple bool flag: isCollide and set it in OnCollisionEnter2D fuction to true.
In LateUpdate function i check this flag:
if( isCollide == true)
// player lost the game
else
// player win the game
But it doesn’t work because it invokes LateUpdate and my bool flag is false then the collision happened after that.
I think I could wait for example 0.5 second after user push the mouse button and then check it was collision or not, but I don’t think it is the best way to solve my problem.
I am a bit confused what your game mechanic is about.
What’s the timeframe to win? If the object does not collide for x seconds?
And why LateUpdate instead of Update?
player push the button and object doesn’t collide.
Loose scenario:
-player push the button but object collides with something
I just need to know that OnCollisionEnter2D invoked or not.
EDIT: Sorry. I made a mistake in my first post.
My object moves and after player push the button this object stops.
When it stops I enable collider componet of this object.
If my object collides with something player loose the game, if not - player win.
It’s not a single update cycle. I just describe my problem in short way.
The problem is how to check it was collide or not, after player push the button, that’s all.
What conditions should I check in Update? My flag isCollide behaves the same in Update and LateUpdate.
I made similar thing. I wait 1.0 second after playerPushTheButon then I check isCollide. But your solution is faster I guess. Thanks for your time and help.