当前位置:网站首页>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);
}边栏推荐
- Node:504 error reporting
- How to choose the appropriate automated testing tools?
- How does win11 unblock the keyboard? Method of unlocking keyboard in win11
- Relationship between URL and URI
- Customer case | China law network, through observing the cloud, greatly shortens the time of fault location
- 648. Word replacement
- 反爬通杀神器
- How to quickly check whether the opening area ratio of steel mesh conforms to ipc7525
- DNS series (I): why does the updated DNS record not take effect?
- Jerry's configuration of TWS cross pairing [article]
猜你喜欢

Two kinds of updates lost and Solutions
![[JDBC Part 1] overview, get connection, CRUD](/img/53/d79f29f102c81c9b0b7b439c78603b.png)
[JDBC Part 1] overview, get connection, CRUD

ByteDance senior engineer interview, easy to get started, fluent

Kirin Xin'an operating system derivative solution | storage multipath management system, effectively improving the reliability of data transmission
![[azure microservice service fabric] the service fabric cluster hangs up because the certificate expires (the upgrade cannot be completed, and the node is unavailable)](/img/35/1bb21c100980eb1075dbbcb922e181.png)
[azure microservice service fabric] the service fabric cluster hangs up because the certificate expires (the upgrade cannot be completed, and the node is unavailable)

Ueeditor custom display insert code

What if the win11u disk does not display? Solution to failure of win11 plug-in USB flash disk

Crawler (17) - Interview (2) | crawler interview question bank

海外代理推荐

【Azure微服务 Service Fabric 】因证书过期导致Service Fabric集群挂掉(升级无法完成,节点不可用)
随机推荐
Pre sale 179000, hengchi 5 can fire? Product power online depends on how it is sold
OpenGL configuration vs2019
OpenGL configure assimp
OpenGL job coordinate system
Implementation method of data platform landing
Paint basic graphics with custompaint
How to realize the movement control of characters in horizontal game
Remember an experience of using selectmany
Leetcode SQL first day
How to turn on win11 game mode? How to turn on game mode in win11
OpenGL job - texture
The strongest installation of the twin tower model, Google is playing "antique" again?
[open source] Net ORM accessing Firebird database
IP网络主动测评系统——X-Vision
Embedded development: how to choose the right RTOS for the project?
DBSync新增对MongoDB、ES的支持
变量与常量
TCP/IP 协议栈
DNS series (I): why does the updated DNS record not take effect?
23. Merge K ascending linked lists -c language