revival/game/Assets/Scripts/Traps/Teleporter.cs

30 lines
681 B
C#

using UnityEngine;
using UnityEngine.Events;
[RequireComponent(typeof(BoxCollider))]
public class Teleporter : MonoBehaviour
{
[SerializeField] private Transform _out;
[SerializeField] private UnityEvent _onTeleport;
private void OnEnable()
{
GetComponent<BoxCollider>().isTrigger = true;
}
private void OnTriggerEnter(Collider col)
{
if (!col.gameObject.TryGetComponent(out CharacterController cc)) return;
var go = col.gameObject;
var outPos = _out.position;
cc.enabled = false;
go.transform.position = outPos;
cc.enabled = true;
}
}