1、首先打开Unity3d,点击creat,接着点击3d object下的cube,创建游戏物体cube。
2、点击creat,创建一个新的脚本,命名为“Roation”。
3、选中脚本,点击鼠标右键弹出菜单,选择打开脚本。
4、按照下图添加下列代码:if(Input.GetKey(KeyCode.Q)){transform.Rotate(0, -25 * Time.deltaTime, 0, Space.Self);}if(Input.GetKey(KeyCode.E)){transform.Rotate(0, 25 * Time.deltaTime, 0, Space.Self);}if(Input.GetKey(KeyCode.Z)){transform.Rotate(-25 * Time.deltaTime, 0, 0, Space.Self);}if(Input.GetKey(KeyCode.C)){transform.Rotate(25 * Time.deltaTime, 0, 0, Space.Self);}
5、完成后ctrl+S保存脚本或者点击附加到Unity,回到Unity界面。
6、鼠标选中我们的脚本拖给cube。
7、点击运行,分别按住QEZC键发现物体可以进行旋转。
8、以上就是控制物体旋转的步骤,希望能对您有所帮助。