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);
}