Created
November 18, 2021 22:04
-
-
Save kurtdekker/1152ceb81a7de7420b796bcca5a86cb9 to your computer and use it in GitHub Desktop.
Lets one object follow another object using only a positional offset
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
// @kurtdekker | |
// Purpose: follows another Transform, maintaining the same offset from it. | |
// Useful for a detached health bar that follows a rotating ship (for instance). | |
public class LateFollow : MonoBehaviour | |
{ | |
public Transform TargetToFollow; | |
Vector3 Offset; | |
void Start () | |
{ | |
Offset = transform.position - TargetToFollow.position; | |
} | |
void LateUpdate () | |
{ | |
transform.position = TargetToFollow.position + Offset; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment