您的位置:首页 > 移动开发 > Unity3D

Unity 摄像机平滑跟随

2017-08-24 17:28 351 查看
using UnityEngine;
public class CameraLag : MonoBehaviour
{
public Transform    attach;
public Transform target;
public float time = 1.0f;

public Vector3 pos;
Vector3 spd = Vector3.zero;

void Start()
{
if ( attach )
pos = attach.position;
}

void LateUpdate()
{
if ( attach )
{
Vector3 cpos = attach.position;

pos = Vector3.SmoothDamp(pos, cpos, ref spd, time);
transform.position = pos;

if ( target )
{
transform.rotation = Quaternion.LookRotation(target.position - pos);
}
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: