Unity摄像机案例

public class FollowTarget : MonoBehaviour
{
    /// <summary> 获得被摄物体的位置 </summary>
    private Transform playerTransfrom;
    /// <summary> 获得起始差值 </summary>
    private Vector3 offset;
    /// <summary> 插值速度 </summary>
    private float smoothing = 3; 

    // Start is called before the first frame update
    void Start()
    {
        playerTransfrom = GameObject.FindGameObjectWithTag("Player").transform;
        offset = transform.position - playerTransfrom.position;
    }

    private void LateUpdate()
    {
        Vector3 offset1 = playerTransfrom.position + playerTransfrom.TransformDirection(offset);
        transform.position = Vector3.Lerp(transform.position, offset1, Time.deltaTime * smoothing);
        //这个相当于让相机望向被摄物体。
        transform.LookAt(playerTransfrom.position);
    }
}
上一篇:跳一跳Unity版(一)——基本功能实现


下一篇:Delaunay三角剖分实现