27 lines
598 B
C#
27 lines
598 B
C#
using UnityEngine;
|
|
|
|
[RequireComponent(typeof(BoxCollider))]
|
|
public class Teleporter : MonoBehaviour
|
|
{
|
|
[SerializeField] private Transform _out;
|
|
|
|
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;
|
|
}
|
|
}
|