Let me start by saying in kinda a newbie, so keep it simple please lol
I was trying to make a portal to teleport an object in Unity. I couldn't figure it out so I looked up a tutorial and found this bit of code. It works fine, except for one tiny issue. The object going through the portal (I just used a sphere) will go back and forth constantly between the portal, essentially becoming stuck in a loop. Is there a way to set a buffer or "cooldown time" on the function so it wont trigger again immediately? I put this code on both of the portals and set the "spawnPoint"s to the other portal. So the orange portal's spawnPoint was the blue portal and vice versa. Here's the code.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Portal : MonoBehaviour
{
public Transform spawnPoint;
// Update is called once per frame
void OnTriggerEnter(Collider other)
{
other.gameObject.transform.position = spawnPoint.position;
}
}
let me know if I wasn't clear enough.