当前位置:网站首页>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);
}边栏推荐
- Get the week start time and week end time of the current date
- [interview arrangement] 0211 game engine server
- OpenGL job - texture
- operator
- How to turn on win11 game mode? How to turn on game mode in win11
- Tcp/ip protocol stack
- [开源] .Net ORM 访问 Firebird 数据库
- Matplotlib快速入门
- null == undefined
- Have you ever been confused? Once a test / development programmer, ignorant gadget C bird upgrade
猜你喜欢

Solve the problem of uni in uni app Request sent a post request without response.

嵌入式开发:如何为项目选择合适的RTOS?

DNS series (I): why does the updated DNS record not take effect?
![[advanced MySQL] index details (I): index data page structure](/img/e7/fe4591a721a71c3c38d6e4448af6af.png)
[advanced MySQL] index details (I): index data page structure

How to realize the movement control of characters in horizontal game
![Jerry's about TWS pairing mode configuration [chapter]](/img/fd/dd1e252617d30dd7147dbab25de5b4.png)
Jerry's about TWS pairing mode configuration [chapter]

Pre sale 179000, hengchi 5 can fire? Product power online depends on how it is sold

Px4 autonomous flight

Application practice | the efficiency of the data warehouse system has been comprehensively improved! Data warehouse construction based on Apache Doris in Tongcheng digital Department

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?
随机推荐
EasyCVR配置中心录像计划页面调整分辨率时的显示优化
OpenGL configure assimp
An in-depth understanding of fp/fn/precision/recall
Main functions of OS, Sys and random Standard Libraries
Talk about relational database and serverless
Jerry's initiation of ear pairing, reconnection, and opening of discoverable and connectable cyclic functions [chapter]
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?
Solve the problem of uni in uni app Request sent a post request without response.
Preparing for the interview and sharing experience
Firefox browser installation impression notes clipping
Antd date component appears in English
Oracle advanced (VI) Oracle expdp/impdp details
npm uninstall和rm直接删除的区别
Win11游戏模式怎么开启?Win11开启游戏模式的方法
Debugging and handling the problem of jamming for about 30s during SSH login
Matplotlib快速入门
Dayu200 experience officer MPPT photovoltaic power generation project dayu200, hi3861, Huawei cloud iotda
OpenGL jobs - shaders
Embedded development: how to choose the right RTOS for the project?
Jerry's key to initiate pairing [chapter]