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

34 lines
793 B
C#

using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using Cinemachine;
using UnityEditorInternal;
using UnityEngine;
using UnityEngine.Rendering;
[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;
}
}