注释:方法非原创,纯笔记,欢迎转载。
准备:1.摄像机 Camera 2.新建C#Script 命名CameraMove
开始:
1.输入:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraMove : MonoBehaviour {
public Transform playerTransform;
public float smoothing;
private Vector3 offset;
void Awake(){
offset = transform.position - playerTransform.position;
}
void FixedUpdate(){
Vector3 newCameraPos = playerTransform.position + offset;
transform.position = Vector3.Lerp (transform.position, newCameraPos, smoothing * Time.deltaTime);
}
}
2.保存,把文件拖到摄像机Camera上;
3.在Scene窗口中选择合适视角,选中摄像机Camera后按住Ctrl+Shift+F移动摄像机到当前视角(也可以手动调整摄像机位置);
4.摄像机Camera属性,把需要锁定视角移动的角色拖入到Player Transform中,Smoothing后面数字输入5;
5.运行即可。