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; } }