You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
719 B
C#
25 lines
719 B
C#
using UnityEngine;
|
|
|
|
public class CameraFollow : MonoBehaviour
|
|
{
|
|
public Transform target; // Reference to the character
|
|
public float smoothSpeed = 0.125f;
|
|
public Vector3 offset;
|
|
public bool isPlaying;
|
|
void Start()
|
|
{
|
|
isPlaying = true;
|
|
offset =target.transform.position- transform.position;
|
|
}
|
|
void LateUpdate()
|
|
{
|
|
if (isPlaying)
|
|
{
|
|
if (target != null)
|
|
{
|
|
Vector3 targetPosition = new Vector3(transform.position.x, target.position.y, transform.position.z);
|
|
transform.position = Vector3.Lerp(transform.position, targetPosition - new Vector3(0, offset.y, 0), smoothSpeed);
|
|
}
|
|
}
|
|
}
|
|
} |