using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using VRTK;
|
|
|
|
public class SmoothFollowBehaviour : MonoBehaviour
|
|
{
|
|
[Header("Base Settings")]
|
|
[SerializeField]
|
|
private Transform m_Target;
|
|
|
|
[SerializeField]
|
|
private float m_SmoothValue = 0.5f;
|
|
|
|
[Header("Teleport")]
|
|
[SerializeField]
|
|
private bool m_snapOnTeleport = false;
|
|
|
|
[SerializeField]
|
|
private VRTK_BasicTeleport m_teleportScript;
|
|
|
|
|
|
private void OnEnable()
|
|
{
|
|
if (m_teleportScript != null)
|
|
m_teleportScript.Teleported += OnTeleport;
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
if (m_teleportScript != null)
|
|
m_teleportScript.Teleported -= OnTeleport;
|
|
}
|
|
|
|
void LateUpdate()
|
|
{
|
|
if (m_Target != null)
|
|
{
|
|
transform.position = Vector3.Lerp(transform.position, m_Target.position, m_SmoothValue);
|
|
transform.rotation = Quaternion.Lerp(transform.rotation, m_Target.rotation, m_SmoothValue);
|
|
}
|
|
}
|
|
|
|
|
|
void OnTeleport(object sender, DestinationMarkerEventArgs e)
|
|
{
|
|
if (m_snapOnTeleport)
|
|
{
|
|
transform.position = m_Target.position;
|
|
transform.rotation = m_Target.rotation;
|
|
}
|
|
|
|
}
|
|
|
|
}
|