Univerisal Teleorter Pad

So ive seen a YT video of someones script for a teleporter in unity2d. ive modified it a bit and its not working, though i recieved no errors. so the idea is to get the transform.position of an object, that im colliding with and teleporting me to that transport.position. the object is the teleporter and the child is the point where i wanna come out. (BTW im pretty new to unity so there might be an obvious dumb mistake made)

thanks in advence.

heres the code:

using UnityEngine;
using System.Collections;

public class movetolocation : MonoBehaviour
{

void OnCollisionEnter2D (Collision2D coll)
{
if (coll.gameObject.tag == “Teleporter”)
{
transform.position = coll.transform.GetChild(0).position;
}
}
}

What is your script attached to? “transform.position” refers to the Transform component of the GameObject your script is attached to.

Please use code tags when you want to post some code.

There are plenty of possbile reasons.
Some of them being:

  • forgot to assign the tag to the teleporter
  • tag spelled incorrectly (it’s case-sensitive)
  • missing Rigidbody2D or CharacterController
  • missing Collider2D
  • forgot to attach the script to the player
    …

As mentioned, there’s a ton of possibilities. Throw a Debug.Log statement and see if collision event is being called. If it is, see if the tag condition is met with another Debug.Log. If it is, you know it’s something else. That’s how you find an issue. That’s how everyone finds the issue.

1 Like