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

30 lines
681 B
C#
Raw Normal View History

2021-04-28 16:58:11 +02:00
using UnityEngine;
2021-05-16 21:00:39 +02:00
using UnityEngine.Events;
2021-04-28 16:58:11 +02:00
[RequireComponent(typeof(BoxCollider))]
public class Teleporter : MonoBehaviour
{
2021-05-11 00:29:49 +02:00
[SerializeField] private Transform _out;
2021-05-16 21:00:39 +02:00
[SerializeField] private UnityEvent _onTeleport;
2021-05-11 00:29:49 +02:00
2021-04-28 16:58:11 +02:00
private void OnEnable()
{
2021-05-11 00:29:49 +02:00
GetComponent<BoxCollider>().isTrigger = true;
2021-04-28 16:58:11 +02:00
}
private void OnTriggerEnter(Collider col)
{
2021-05-11 00:29:49 +02:00
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;
2021-04-28 16:58:11 +02:00
}
}