mirror of
https://udrimavric.com/MAVRIC/Stratasys-450mc-VR.git
synced 2025-01-23 07:38:33 -05:00
55 lines
1.1 KiB
C#
55 lines
1.1 KiB
C#
|
using System;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
|
||
|
[ExecuteAlways]
|
||
|
public class FollowTransform : MonoBehaviour
|
||
|
{
|
||
|
[SerializeField] private Transform target;
|
||
|
|
||
|
[SerializeField] private bool updatePosition = true;
|
||
|
[SerializeField] private bool updateRotation = true;
|
||
|
[SerializeField] private bool updateEveryFrame = false;
|
||
|
|
||
|
[SerializeField] private Vector3 positionOffset;
|
||
|
|
||
|
private void Awake()
|
||
|
{
|
||
|
if (target == null)
|
||
|
{
|
||
|
this.enabled = false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void OnEnable()
|
||
|
{
|
||
|
UpdatePosition();
|
||
|
UpdateRotation();
|
||
|
}
|
||
|
|
||
|
private void Update()
|
||
|
{
|
||
|
if (!updateEveryFrame) return;
|
||
|
|
||
|
UpdatePosition();
|
||
|
UpdateRotation();
|
||
|
}
|
||
|
|
||
|
private void UpdatePosition()
|
||
|
{
|
||
|
if (!updatePosition) return;
|
||
|
if (target == null) return;
|
||
|
|
||
|
transform.position = target.position + positionOffset;
|
||
|
}
|
||
|
|
||
|
private void UpdateRotation()
|
||
|
{
|
||
|
if (!updateRotation) return;
|
||
|
if (target == null) return;
|
||
|
|
||
|
transform.rotation = target.rotation;
|
||
|
}
|
||
|
}
|