mirror of
https://github.com/RaindropViewer/RaindropViewer.git
synced 2026-07-27 22:11:39 +00:00
29 lines
743 B
C#
29 lines
743 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class simpleFollow : MonoBehaviour
|
|
{
|
|
public Transform target;
|
|
|
|
public float smoothTime = 0.3F;
|
|
private Vector3 velocity = Vector3.zero;
|
|
|
|
void Start()
|
|
{
|
|
if (!target)
|
|
{
|
|
Debug.LogWarning("simple camera follow has no target");
|
|
}
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
// Define a target position above and behind the target transform
|
|
Vector3 targetPosition = target.TransformPoint(new Vector3(0, 5, -10));
|
|
|
|
// Smoothly move the camera towards that target position
|
|
transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref velocity, smoothTime);
|
|
}
|
|
}
|