unity3d 简单的相机跟随目标

来源:互联网 发布:web软件测试工具 编辑:程序博客网 时间:2024/06/05 08:18

将该脚本挂在要跟随的camera上

将要被跟随的目标设为target,就可以实现了

using UnityEngine;using System.Collections;public class FollowTaget : MonoBehaviour{    public Transform target;//目标    private Transform mRoot;//相机    [SerializeField]    private float moveSpeed = 5;    private Vector3 offset;//目标与相机的距离    void Awake()    {        mRoot = this.transform;        offset = mRoot.position - target.position;    }    void LateUpdate()    {        mRoot.position = Vector3.Lerp(mRoot.position, target.position + offset, moveSpeed * Time.deltaTime);    }}


0 0
原创粉丝点击