当前位置:网站首页>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);
}
边栏推荐
- Tcp/ip protocol stack
- Use partial derivatives to display normals in unity
- L2: current situation, prospects and pain points of ZK Rollup
- Use blocconsumer to build responsive components and monitor status at the same time
- NVR hard disk video recorder is connected to easycvr through the national standard gb28181 protocol. What is the reason why the device channel information is not displayed?
- Welcome to CSDN markdown editor
- [open source] Net ORM accessing Firebird database
- How to close eslint related rules
- OpenGL configure assimp
- Pre sale 179000, hengchi 5 can fire? Product power online depends on how it is sold
猜你喜欢
. Net automapper use
The strongest installation of the twin tower model, Google is playing "antique" again?
[open source] Net ORM accessing Firebird database
EasyCVR配置中心录像计划页面调整分辨率时的显示优化
How to realize the movement control of characters in horizontal game
应用实践 | 数仓体系效率全面提升!同程数科基于 Apache Doris 的数据仓库建设
NVR hard disk video recorder is connected to easycvr through the national standard gb28181 protocol. What is the reason why the device channel information is not displayed?
How does win11 unblock the keyboard? Method of unlocking keyboard in win11
It's worth seeing. Interview sites and interview skills
Application practice | the efficiency of the data warehouse system has been comprehensively improved! Data warehouse construction based on Apache Doris in Tongcheng digital Department
随机推荐
NVR hard disk video recorder is connected to easycvr through the national standard gb28181 protocol. What is the reason why the device channel information is not displayed?
Reinforcement learning - learning notes 9 | multi step TD target
如何选择合适的自动化测试工具?
vite Unrestricted file system access to
How does win11 unblock the keyboard? Method of unlocking keyboard in win11
#DAYU200体验官#MPPT光伏发电项目 DAYU200、Hi3861、华为云IotDA
Anti climbing killer
Win11游戏模式怎么开启?Win11开启游戏模式的方法
PKPM 2020软件安装包下载及安装教程
Interview question 01.02 Determine whether it is character rearrangement - auxiliary array algorithm
Jerry's about TWS pairing mode configuration [chapter]
npm uninstall和rm直接删除的区别
[开源] .Net ORM 访问 Firebird 数据库
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?
Index summary (assault version)
Have you ever been confused? Once a test / development programmer, ignorant gadget C bird upgrade
Remove the default background color of chrome input input box
How to choose the appropriate automated testing tools?
TCP/IP 协议栈
OpenGL job coordinate system