在3D游戏开发的过程中,第三人称的摄像机是不可逃避的问题。
1.我先献上摄像机缩放,跟随,右键调节角度的代码:
主要是利用差值计算来改变位置,很简单,没什么可说的。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LookAtPlayer : MonoBehaviour {
private GameObject target;
private Vector3 offset;
void Start () {
target = GameObject.FindGameObjectWithTag("Player");
offset = target.transform.position - this.transform.position;
}
void LateUpdate()
{
this.transform.position = target.transform.position - offset;
Rotate();
Scale();
}
//缩放
private void Scale()
{
float dis = offset.magnitude;
dis += Input.GetAxis("Mouse ScrollWheel") * 5;
if (dis < 1.5f || dis > 5)
{
return;
}
offset = offset.normalized * dis;
}
//左右上下移动
p