当前位置:网站首页>Unity development --- the mouse controls the camera to move, rotate and zoom
Unity development --- the mouse controls the camera to move, rotate and zoom
2022-07-07 22:22:00 【Hey, hey, hey, hey, hey】
void Update()
{
float scrollWheel = Input.GetAxis("Mouse ScrollWheel");
if(scrollWheel != 0)
{
Camera_Scale(scrollWheel);
}
else if(Input.GetKeyDown(KeyCode.LeftAlt))// Press down Alt key
{
if(Input.GetMouseButton(0))
{
Camera_Rotate();
}
}
else if(Input.GetMouseButton(2))
{
Camera_Move();
}
}
private void Camera_Scale(float scrollWheel)
{
scrollWheel = scrollWheel * Time.DeltaTime * 500;
transform.Translate(Vector3.forward * wheel);
}
private void Camera_Rotate()
{
float mouseX = Input.GetAxis("Mouse X");
float mouseY = Input.GetAxis("Mouse Y");
transform.RotateAround(transform.position, Vector3.up, mouseX * 5);
transform.RotateAround(transform.position, transform.right, -mouseY * 5);
}
private void Camera_Move()
{
float mouseX = Input.GetAxis("Mouse X");
float mouseY = Input.GetAxis("Mouse Y");
transform.Translate(Vector3.left * mouseX);
transform.Translate(Vector3.up * mouseY * -1);
}边栏推荐
- L'enregistreur de disque dur NVR est connecté à easycvr par le Protocole GB 28181. Quelle est la raison pour laquelle l'information sur le canal de l'appareil n'est pas affichée?
- Reinforcement learning - learning notes 9 | multi step TD target
- Talk about relational database and serverless
- Use blocconsumer to build responsive components and monitor status at the same time
- 如何实现横版游戏中角色的移动控制
- 【Azure微服务 Service Fabric 】在SF节点中开启Performance Monitor及设置抓取进程的方式
- Kaggle-Titanic
- Firefox browser installation impression notes clipping
- OpenGL job - texture
- Get the week start time and week end time of the current date
猜你喜欢

Embedded development: how to choose the right RTOS for the project?

Kirin Xin'an operating system derivative solution | storage multipath management system, effectively improving the reliability of data transmission

使用 CustomPaint 绘制基本图形

UWA问答精选

The strongest installation of the twin tower model, Google is playing "antique" again?

为什么Win11不能显示秒数?Win11时间不显示秒怎么解决?

Index summary (assault version)

NVR硬盤錄像機通過國標GB28181協議接入EasyCVR,設備通道信息不顯示是什麼原因?

使用 BlocConsumer 同时构建响应式组件和监听状态
![[advanced MySQL] index details (I): index data page structure](/img/e7/fe4591a721a71c3c38d6e4448af6af.png)
[advanced MySQL] index details (I): index data page structure
随机推荐
客户案例|华律网,通过观测云大幅缩短故障定位时间
[azure microservice service fabric] the service fabric cluster hangs up because the certificate expires (the upgrade cannot be completed, and the node is unavailable)
Main functions of OS, Sys and random Standard Libraries
ByteDance Android interview, summary of knowledge points + analysis of interview questions
Jerry's initiation of ear pairing, reconnection, and opening of discoverable and connectable cyclic functions [chapter]
Get the week start time and week end time of the current date
Oracle advanced (VI) Oracle expdp/impdp details
Ternary expressions, generative expressions, anonymous functions
大数据开源项目,一站式全自动化全生命周期运维管家ChengYing(承影)走向何方?
. Net automapper use
OpeGL personal notes - lights
应用实践 | 数仓体系效率全面提升!同程数科基于 Apache Doris 的数据仓库建设
null == undefined
Two kinds of updates lost and Solutions
Implementation method of data platform landing
VTOL in Px4_ att_ Control source code analysis [supplement]
Index summary (assault version)
Remove the default background color of chrome input input box
Use blocconsumer to build responsive components and monitor status at the same time
Jerry's manual matching method [chapter]