- Home /
Script Delay with Teleport
Hi
I have written this script to make my character teleport from point a to b. it worked fine, but when i tired the reverse to get from point b to a; it wouldn't work. the character kept getting teleported back to point a. I'm new to scripting so can you guys help with adding a delay into this script? Also I used empty GameObjects as the exit.
Thank you
Point A to B
using UnityEngine; using System.Collections;
public class Teleporter : MonoBehaviour { public Transform exit; static Transform last;
void OnTriggerEnter2D (Collider2D Gamecornerwallwithdoor)
{
if (exit == last)
return;
TeleportToExit(collider2D);
}
void OnTriggerExit2D ()
{
if (exit == last)
last = null;
return;
}
void TeleportToExit (Collider2D gamedoor)
{
last = transform;
collider2D.transform.position = exit.transform.position;
}
}
Point B to A
using UnityEngine; using System.Collections;
public class Teleport2 : MonoBehaviour { public Transform exit; static Transform last;
void OnTriggerEnter2D (Collider2D GameEntrance)
{
if (exit == last)
return;
TeleportToExit(collider2D);
}
void OnTriggerExit2D ()
{
if (exit == last)
last = null;
return;
}
void TeleportToExit (Collider2D GameEnt)
{
last = transform;
collider2D.transform.position = exit.transform.position;
}
}
P.S the game is a 2-D, Top-Down, Third-Person RPG Style game
Comment