SmoothFollow.cs
794 Bytes
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SmoothFollow : MonoBehaviour
{
public Transform target;
public float followSpeed = 1;
public bool followX, followY, followZ;
private Vector3 _follow;
void Start()
{
_follow = Vector3.zero;
if (followX)
_follow += Vector3.right;
if (followY)
_follow += Vector3.up;
if (followZ)
_follow += Vector3.forward;
}
void LateUpdate()
{
Vector3 followPos = new Vector3(target.position.x * _follow.x, target.position.y * _follow.y,
target.position.z * _follow.z);
transform.position = Vector3.Lerp(transform.position, followPos, Time.deltaTime * followSpeed * 2);
}
}