In my game I need to detect the collision of the ball touching the walls when a certain game state (“Action Time”) is active. So when the game is started and the ball touches the walls, nothing should happen. But when the Action Time is active, the Ball changes its position whenever it touches the walls.
I could implement this but the issue is the following: when the ball is already touching the wall and then the game states changes to “Action Time” the detection is not registered as I am using OnCollisionEnter.
This is my code attached to the ball:
private void OnCollisionEnter2D(Collision2D collision)
if (collision.gameObject.tag == "wall")
A similiar question was asked here, where the solution is OnCollisionStay, but I cannot use OnCollisionStay since the Ball in my game doesn’t bounce back. So entering and leaving the touch are at two different times.
There are two scenarios:
- “ActionTime” is active and then Ball touches the wall → this works perfectly
- Ball touches the wall and doesn’t let go as if it is glued and THEN “ActionTime” becomes active → no collision detection. Position needs to be changed as soon as the touch begins.
What can I do?