23 lines
548 B
C#
23 lines
548 B
C#
using UnityEngine;
|
|
|
|
public class FollowTarget : MonoBehaviour
|
|
{
|
|
[SerializeField] Transform target;
|
|
[SerializeField]
|
|
[Range(0f, 1f)]
|
|
float lerpSpeed;
|
|
|
|
Vector3 offset;
|
|
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
void Start()
|
|
{
|
|
offset = transform.position - target.position;
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void FixedUpdate()
|
|
{
|
|
transform.position = Vector3.Lerp(transform.position, target.position + offset, lerpSpeed);
|
|
}
|
|
}
|