- Home /
Teleports 2D,teleport scirpt 2D
hello I am new to unity and I am doing a 2D rpg and I have a problem with the teleporters (that take you from one area to another area) you will see I put the script with box collider and GameObject but the player does not collide with the teleport, much less teleports why I need help here I leave my script thanks
-Thomas
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class TP : MonoBehaviour {
public GameObject portal;
void Awake() {
GetComponent<SpriteRenderer>().enabled = false;
transform.GetChild(0).GetComponent<SpriteRenderer>().enabled = false;
}
void OnTriggerEnter2D(Collision2D) {
if (other.tag == "Player"){
other.transform.position = portal.transform.GetChild(0).transform.position;
}
}
} ,hello I have a problem with this script, you see I am trying to do a 2D rpg and supposedly this script would be the one of the teleports from one area to another but it does not work it does not detect the collision, much less the teleportation someone help me?
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class TP : MonoBehaviour {
public GameObject portal;
void Awake() {
GetComponent<SpriteRenderer>().enabled = false;
transform.GetChild(0).GetComponent<SpriteRenderer>().enabled = false;
}
void OnTriggerEnter2D(Collider2D other){
if (other.tag == "Player"){
other.transform.position = portal.transform.GetChild(0).transform.position;
}
}
}
Your answer
Follow this Question
Related Questions
cant play game because of InternalEngineBridge error 0 Answers
How can I spawn different GameObjects using IEnumerator? 1 Answer
2D animation issue 0 Answers
4 C# errors Endless Runner 0 Answers