unity鼠标固定在屏幕中间_unity。。。完美简单解决靠鼠标在屏幕上的移动来控制相机水平,垂直旋转的c#脚本...

本文介绍了一种解决Unity3D中通过鼠标移动控制相机水平和垂直旋转的方法,包括三个版本的C#脚本,最终版本能够限制旋转角度并保持视野中心对准目标对象。
摘要由CSDN通过智能技术生成

花了一天时间琢磨这个,看网上的解决办法。。没几个彻底解决的。。。都是说什么方法复杂。。让我们自己去看视频教程。。!!!!

感觉跟没有回答一样。。。。自己也是很多方法都试了。。不是有这种问题,就是那种问题。。。。。。烦!!!最后自己琢磨出这个不是办法的办法。。。。。。

虽然没有用到什么高深的东西,复杂的算法。。。。但是自己花时间琢磨的。亲测效果还过得去。注意有三个版本(全当学习过程了),最后版本为最简单最完美的.

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 Quaternion();

  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值