- Home /
I want teleport exit which it does specific Colider2D and to transport you to a specific one target how do I do that?
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;
}
}
Answer by Legend_Bacon · Mar 20, 2018 at 04:54 PM
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TeleportExit : $$anonymous$$onoBehaviour {
public Transform targets;
public Transform play;
public GameObject theObject;
// Update is called once per frame
private void OnTriggerExit2D(Colider2D theObject)
{
if (theObject.gameObject.CompareTags("playArea"))
{
play.position = targets.position;
}
}
}
i have this error and not run
Assets/Scrept/TeleportExit.cs(11,34): error CS0246: The type or namespace name `Colider2D' could not be found. Are you missing an assembly reference?
Ah, it seems I misspelled the word "Collider2D". Just add another "l" in there and you'll be fine!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TeleportExit : $$anonymous$$onoBehaviour {
public Transform targets;
public Transform play;
public GameObject theObject;
// Update is called once per frame
private void OnTriggerExit2D(Collider2D theObject)
{
if (theObject.gameObject.CompareTags("playArea"))
{
play.position = targets.position;
}
}
}
the same problem
Assets/Scrept/TeleportExit.cs(13,23): error CS1061: Type
UnityEngine.Collider2D' does not contain a definition for
CompareTags' and no extension methodCompareTags' of type
UnityEngine.Collider2D' could be found. Are you missing an assembly reference?
Your answer

Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
2D - Creating a basic teleport system 0 Answers
Teleport Not Working in Unity 2D 1 Answer
Having problems with my teleport tiles and respawning 1 Answer