Hi. i want to teleport the player when it hits something but i don't know why it doesn't work.
this is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class teleport : MonoBehaviour
{
public GameObject spawner;
public GameObject player;
// Start is called before the first frame update
void Start()
{
}
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
player.transform.position = new Vector3(spawner.transform.position.x, spawner.transform.position.y, spawner.transform.position.z);
}
}
}
If anyone knows why I would appreciate if you could tell me.