Unity3d 鼠标滚动拉近模型、鼠标右键旋转模型、鼠标中键拖拽模型
来源:互联网 发布:淘宝客关闭后多久生效 编辑:程序博客网 时间:2024/05/13 17:30
鼠标滚动拉近模型、鼠标右键旋转模型、鼠标中键拖拽模型
把如下代码直接挂在摄像机对象上
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using UnityEngine;
using System.Collections;
public class Script_07_11 : MonoBehaviour
{
public Transform target;
private int MouseWheelSensitivity = 1;
private int MouseZoomMin = 1;
private int MouseZoomMax = 5;
private float normalDistance = 3;
private Vector3 normalized;
private float xSpeed = 250.0f;
private float ySpeed = 120.0f;
private int yMinLimit = -20;
private int yMaxLimit = 80;
private float x = 0.0f;
private float y = 0.0f;
private Vector3 screenPoint;
private Vector3 offset;
private Quaternion rotation = Quaternion.Euler(new Vector3(30f,0f,0f));
private Vector3 CameraTarget;
void Start ()
{
CameraTarget = target.position;
float z = target.transform.position.z - normalDistance;
transform.position = rotation * new Vector3(transform.position.x,transform.position.y,z);
transform.LookAt(target);
var angles = transform.eulerAngles;
x = angles.y;
y = angles.x;
}
void Update ()
{
if(Input.GetMouseButton(1))
{
x += Input.GetAxis(“Mouse X”) * xSpeed * 0.02f;
y -= Input.GetAxis(“Mouse Y”) * ySpeed * 0.02f;
y = ClampAngle(y, yMinLimit, yMaxLimit);
var rotation = Quaternion.Euler(y, x, 0);
var position = rotation * new Vector3(0.0f, 0.0f, -normalDistance) + CameraTarget;
transform.rotation = rotation;
transform.position = position;
}else if (Input.GetAxis(“Mouse ScrollWheel”) != 0)
{
normalized = (transform.position - CameraTarget).normalized;
if (normalDistance >= MouseZoomMin && normalDistance <= MouseZoomMax)
{
normalDistance -= Input.GetAxis(“Mouse ScrollWheel”) * MouseWheelSensitivity;
}
if (normalDistance < MouseZoomMin)
{
normalDistance = MouseZoomMin;
}
if (normalDistance > MouseZoomMax)
{
normalDistance = MouseZoomMax;
}
transform.position = normalized * normalDistance;
}else if(Input.GetMouseButtonDown(2))
{
screenPoint = Camera.main.WorldToScreenPoint(target.transform.position);
offset = target.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
}
if(Input.GetMouseButton(2))
{
Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
Vector3 curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset;
target.transform.position = curPosition;
}
transform.LookAt(CameraTarget);
}
static float ClampAngle (float angle , float min ,float max)
{
if (angle < -360)
angle += 360;
if (angle > 360)
angle -= 360;
return Mathf.Clamp (angle, min, max);
}
}
最后是工程下载地址:http://vdisk.weibo.com/s/Dorl2
阅读全文
0 0
- Unity3d 鼠标滚动拉近模型、鼠标右键旋转模型、鼠标中键拖拽模型
- 鼠标拉近旋转拖拽模型
- 鼠标拉近旋转拖拽模型
- Unity3d 拖动鼠标旋转模型
- unity3d 2d游戏之鼠标拉近旋转拖拽模型
- unity3d 2d游戏鼠标拉近旋转拖拽模型操作
- [Unity3d]鼠标旋转缩放拖动模型
- 手指/鼠标 360度旋转模型脚本
- threejs 鼠标移动控制模型旋转
- Unity3d 用鼠标拾取模型的顶点
- Unity3d 用鼠标拾取模型的顶点
- unity鼠标左键拖拽旋转模型滚轮放大缩小模型
- 鼠标控件模型
- unityd 模型跟随鼠标移动,鼠标隐藏
- Unity3D导入外部任务模型无法触发鼠标事件解决方案
- Unity3d 用鼠标拾取模型的顶点
- unity3d鼠标滚轮实现摄像头拉近后退
- unity3d鼠标滑动UIImage从而实现3D模型在UIImage上的左右旋转(RawImage映射)
- 请求发送者与接收者解耦——命令模式(六)
- @result标签 type设置为redirect 导致action各属性无法传给前台表单
- python库之os+os.path
- ArcGIS API for JavaScript 解决identify Task 和QueryTask查询结果限制(1000)问题
- 搭建一个 zookeeper集群
- Unity3d 鼠标滚动拉近模型、鼠标右键旋转模型、鼠标中键拖拽模型
- netstat命令
- vCenter服务不能启动的处理过程
- 显函数和隐函数
- 【linxu笔记】redhat6.4 Server更换yum,便于安装软件
- Java for Web学习笔记(九八):持久化初探(3)JPA小例子(上)
- 换种思路实现RecyclerView嵌套RecyclerView(购物车)复杂效果
- 关于c++中vector的使用
- -精通正则表达式-第三版-第2章笔记