using System; using System.Collections; using System.Collections.Generic; using UnityEngine; [RequireComponent(typeof(BoxCollider))] public class Teleporter : MonoBehaviour { [SerializeField] private Teleporter _other; public bool IsSender => _sender; [SerializeField] private bool _sender; private void OnValidate() { if (!_other) return; if (IsSender && _other.IsSender) { Debug.LogError("two senders linked", this); } if (!IsSender && !_other.IsSender) { Debug.LogError("two receivers linked", this); } } private void OnEnable() { var box = GetComponent(); if (IsSender) { box.isTrigger = true; } else { box.enabled = false; } } private void OnTriggerEnter(Collider col) { var trans = col.transform; var pos = trans.position - transform.position; trans.position = _other.transform.position + pos; } }