main Camera参数设置:
Projection:投影方式,分为透视投影和正交投影
(透视投影物体会随着相机距离的大小而变化,正交投影则物体大小不会因为距离远近而变化。
参考博客:https://blog.youkuaiyun.com/aaronmorgan/article/details/78727773)
Size:视野大小 (正交模式的参数)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraFollow : MonoBehaviour {
public GameObject Player;
private Vector3 offset;
private float smoothing = 5f;//Camera移动到目标位置的速度
// Use this for initialization
void Start () {
offset = transform.position - Player.transform.position;
}
// Update is called once per frame
void FixedUpdate () {
Vector3 tartgetCamPos = Player.transform.position + offset;
transform.position = Vector3.Lerp(transform.position, tartgetCamPos, smoothing * Time.deltaTime);//tartgetCamPos;
}
}
- Lerp是 插值 的概念,这边简单来说就是使相机平滑的移动而不是瞬间移位。
- 把CameraFollow.cs拖到Player上。
- 把Player设为Prefabs,这一步主要是方便我们导出导入Player。
1281

被折叠的 条评论
为什么被折叠?



