35 lines
917 B
C#
35 lines
917 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class TeleportObject : MonoBehaviour
|
|
{
|
|
[SerializeField] private Transform ObjectToTeleport;
|
|
[SerializeField] private Transform TeleportPosition;
|
|
private bool Teleported;
|
|
public bool localSpace;
|
|
|
|
private void OnTriggerEnter(Collider col)
|
|
{
|
|
if(col.gameObject.tag == "Player" && !Teleported)
|
|
{
|
|
_TeleportObject();
|
|
Teleported = true;
|
|
}
|
|
}
|
|
|
|
public void _TeleportObject()
|
|
{
|
|
if (!localSpace)
|
|
{
|
|
ObjectToTeleport.position = TeleportPosition.position;
|
|
ObjectToTeleport.rotation = TeleportPosition.rotation;
|
|
}
|
|
else
|
|
{
|
|
ObjectToTeleport.localPosition = TeleportPosition.localPosition;
|
|
ObjectToTeleport.localRotation = TeleportPosition.localRotation;
|
|
}
|
|
}
|
|
}
|