花了一天时间琢磨这个,看网上的解决办法。。没几个彻底解决的。。。都是说什么方法复杂。。让我们自己去看视频教程。。!!!!
感觉跟没有回答一样。。。。自己也是很多方法都试了。。不是有这种问题,就是那种问题。。。。。。烦!!!最后自己琢磨出这个不是办法的办法。。。。。。
虽然没有用到什么高深的东西,复杂的算法。。。。但是自己花时间琢磨的。亲测效果还过得去。注意有三个版本(全当学习过程了),最后版本为最简单最完美的.
using UnityEngine;
using System.Collections;public class CameraFollow : MonoBehaviour
{
public float V_upAngle; // 屏幕从z轴向上抬的高度的限制
public float V_downAngle; //屏幕从z轴向下低头的限制
public float H_Angle; //屏幕左右旋转的最大角度的限制。绕y轴
public float smooth; // how smooth the camera movement is
public float distance_obj;
public float distance_h;
public Transform targe_position; //player
private Vector3 mouse_point;
private float screen_w; //屏幕信息
private float screen_h;
private float H_unit_rotation; //鼠标在屏幕移动距离投射到三维世界的角度旋转单位大小
private float V_up_unit_rotation;
private float V_down_unit_rotation;
private Vector3 screen_center;
private Quaternion center_rotation; //最终旋转结果
private Quaternion current_rotation_H; //水平旋转结果
private Quaternion current_rotation_V; //垂直旋转结果
void Start()
{
center_rotation = new Quat