I have this building in my game where I want to be accessed through this door. So when you are close enough to the door it teleports you to the other side. Although for me this doesn’t work. It doesn’t teleport the player anywhere. Except if I change the “if distance <= minDist” to “if distance >= minDist”. My player uses Character Controller. Help would be appreciated. ![]()
Here’s my code?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Door : MonoBehaviour
{
public Transform other;
float minDist = 5;
public Transform teleport;
public GameObject player;
public float distance;
void Start()
{
}
void Update()
{
if (other)
{
distance = Vector3.Distance(transform.position, other.transform.position);
if (Input.GetKeyDown(KeyCode.E))
{
if (distance < minDist)
{
player.transform.position = teleport.transform.position;
}
}
}
}
}