当前位置:网站首页>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);
}
边栏推荐
- Debugging and handling the problem of jamming for about 30s during SSH login
- [azure microservice service fabric] the service fabric cluster hangs up because the certificate expires (the upgrade cannot be completed, and the node is unavailable)
- 如何选择合适的自动化测试工具?
- Jerry's manual matching method [chapter]
- Ternary expressions, generative expressions, anonymous functions
- Firefox browser installation impression notes clipping
- OpenGL jobs - shaders
- Remember aximp once Use of exe tool
- Record problems fgui tween animation will be inexplicably killed
- 强化学习-学习笔记9 | Multi-Step-TD-Target
猜你喜欢
如何实现横版游戏中角色的移动控制
OpenGL configuration vs2019
Pre sale 179000, hengchi 5 can fire? Product power online depends on how it is sold
VTOL in Px4_ att_ Control source code analysis [supplement]
应用实践 | 数仓体系效率全面提升!同程数科基于 Apache Doris 的数据仓库建设
648. Word replacement
Reptile combat (VII): pictures of the king of reptiles' heroes
Vs custom template - take the custom class template as an example
[open source] Net ORM accessing Firebird database
大数据开源项目,一站式全自动化全生命周期运维管家ChengYing(承影)走向何方?
随机推荐
嵌入式开发:如何为项目选择合适的RTOS?
Interview question 01.02 Determine whether it is character rearrangement - auxiliary array algorithm
How to turn on win11 game mode? How to turn on game mode in win11
Record a garbled code during servlet learning
How does win11 time display the day of the week? How does win11 display the day of the week today?
How to write an augmented matrix into TXT file
ByteDance Android interview, summary of knowledge points + analysis of interview questions
Dbsync adds support for mongodb and ES
Ueeditor custom display insert code
Talk about relational database and serverless
[open source] Net ORM accessing Firebird database
Jerry's configuration of TWS cross pairing [article]
Reinforcement learning - learning notes 9 | multi step TD target
Jerry's manual matching method [chapter]
Kaggle-Titanic
MIT6.S081-Lab9 FS [2021Fall]
Paint basic graphics with custompaint
[interview arrangement] 0211 game engine server
How polardb-x does distributed database hotspot analysis
The strongest installation of the twin tower model, Google is playing "antique" again?