Hi. I want to when something is colliding with my collider that is a trigger wait for a few seconds and then check again if these objects are still colliding.
How would i do that?
What i got right now is
IEnumerator OnTriggerEnter(Collider collider)
{
yield return new WaitForSeconds(2);
/* Check if collider and gameobjects collider is still
colliding, but how? */
}
If anyone is searching for 2D Version, here it is:
bool collided = false;
IEnumerator OnTriggerEnter2D(Collider2D collider)
{
collided = true; //change collided to true
yield return new WaitForSeconds(2); //wait 2 seconds
if (collided == true) //check if collided is still true
{
//Action after 2 seconds trigger.
}
}
//Turns bool collided to false if there is no trigger anymore.
private void OnTriggerExit2D(Collider2D collision)
{
collided = false;
}