Prevent 2 teleports infinite loop. OnTriggerEnter

Hi, I am rookie. I’m having in my game 2 teleports (instantiates) leading to each other in space. How exclude infinite loop, when you going in first teleport. Player is needed time to prohibit ontriggerenter function for few seconds to be able move from teleport.
I have tried this, but it still looping, but after yield time.

 bool collided;
IEnumerator OnTriggerEnter(Collider collider)
{
     collided = true;
     yield return new WaitForSeconds(2);
     if (collided) {
         // move object to teleport2 position
     }
}
void OnCollisionExit () {
     collided = false;
}

Its a the third day when I am puzzled. I have tried simple countdown timer + bool variable(count-= Time.deltaTime in Update), but its not working to. What I’m gonna do now? Pls tell me a tip :frowning:

A typical error is not knowing IEnumerator. Read a few articles about it. Use the “yield return null” function;

Easiest approach is probably to make the player disregard teleport commands for a short period after successfully teleporting. The destination teleport will fire, but the player will disregard it until the disregard timer expires, then teleports will start working again when you enter them.

Can you write a simply piece of code demonstrate how to do this with ontriggerenter function, please?

You cannot sprinkle code into another project like salt and pepper. Integration and actual understanding is a prerequisite.

What I am suggesting you try is an extremely common game mechanism known as a “cooldown timer.”

There are lots of tutorial videos on Google/Youtube explaining how to make a cooldown timer, and if you complete such a tutorial as well as understand the portions related to counting a timer down and inhibiting a behavior, you should have no problem integrating it into your use case above.