29 lines
670 B
C#
29 lines
670 B
C#
using UnityEngine;
|
|
|
|
public class TeleportOnTrigger : MonoBehaviour
|
|
{
|
|
[Header("Teleport Target")]
|
|
public Transform targetPosition;
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
{
|
|
if (targetPosition == null) return;
|
|
|
|
Rigidbody rb = other.attachedRigidbody;
|
|
|
|
if (rb != null)
|
|
{
|
|
// STOP ALL MOTION
|
|
rb.linearVelocity = Vector3.zero;
|
|
rb.angularVelocity = Vector3.zero;
|
|
|
|
// TELEPORT
|
|
rb.position = targetPosition.position;
|
|
}
|
|
else
|
|
{
|
|
// Non-physics objects
|
|
other.transform.position = targetPosition.position;
|
|
}
|
|
}
|
|
} |