- Home /
OnCollisionStay2D deactivates after a short amount of time
I'm pretty new to Unity and I'm currently experimenting around.
Situation: I have a sphere which is the Player. The sphere is standing on a plane. By pressing "s" I want to deactivate the plane, so that the player falls through, then reactivate it.
While moving this works perfectly fine.
But after not moving for maybe half a second, pressing "s" does not do anything.
void OnCollisionStay2D(Collision2D collision)
{
if (Input.GetKeyDown("s") && collision.gameObject.tag == "plane")
{
collision.gameObject.SetActive(false);
StartCoroutine(SetActiveAfterTime(1f, collision.gameObject));
}
}
IEnumerator SetActiveAfterTime(float time,GameObject go) {
yield return new WaitForSeconds(time);
go.SetActive(true);
}
Answer by Larry-Dietz · Jan 01, 2018 at 04:37 PM
Try changing the Sleep Mode on your RigidBody2D to Never Sleep, and see if that helps.
-Larry
Your answer
Follow this Question
Related Questions
How would i calculate the size of a 2D area closed off by multiple colliders? 1 Answer
2D Detect collisions of a 2D block only on left/right (not top/bottom) 0 Answers
How to remove a specific prefab from a List? 1 Answer
Firing Projectiles in the same direction as my character is looking. 1 Answer
How to move Instantiated 2D objects by 0.5 using arrows(or mouse) 1 Answer