- Home /
Question by
WerewoofPrime · Oct 09, 2021 at 10:41 PM ·
c#colliderpositiontagteleporting
how to teleport player to another gameobject using the players tag?
hello! I have a problem. I have a script that teleports the player to a specific gameobject when the player collides with another specific gameobject. the script i have used to work fine but now the player is an instantiation of a prefab, so I need to call to the player that is in the scene because he will get destroyed and instantiated multiple times throughout my game. I was wondering if there was a way to teleport the player by finding an object with the tag "ThePlayer" then teleporting it to the target gameobject. here is my script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Teleport : MonoBehaviour
{
public Transform teleportTarget;
public GameObject Player;
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("ThePlayer"))
{
Player.transform.position = teleportTarget.transform.position;
}
}
Comment
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
C# if(Physics2D.CircleCast();) Not Returning True 1 Answer
łatwy problem dla początkujących z kolizjami. 1 Answer
How can to convert it on c#? 1 Answer