I want teleport exit which it does specific Colider2D and to transport you to a specific one target how do I do that?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TeleportExit : MonoBehaviour {
public Transform targets;
public Transform play;
public GameObject theObject;
// Update is called once per frame
void OnTriggerExit2D(Collider2D theObject)
{
play.position = targets.position;
}
}
Hello there,
What you want to do here is give the object you are colliding with a tag that you can identify. If you want to know when the Player exits your play area, then simply give your play area the tag “playArea”.
Then, you can do this:
private void OnTriggerExit2D(Collider2D theObject)
{
if(theObject.gameObject.CompareTag("playArea"))
{
play.position = targets.position;
}
}
To assign a tag to an object, click on it and then go top right to “Tag”. Not that you can also add custom ones.
Also, quick note: You shouldn’t have a GameObject called “theObject” if your Collider2D has the same name on Trigger Exit.
Hope that helps!
Cheers,
~LegendBacon