50 lines
1.1 KiB
C#
50 lines
1.1 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
[RequireComponent(typeof(BoxCollider))]
|
|
public class Teleporter : MonoBehaviour
|
|
{
|
|
[SerializeField] private
|
|
|
|
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<BoxCollider>();
|
|
|
|
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;
|
|
}
|
|
}
|