Unity
Screen.sleepTimeout:A power saving setting, allowing the screen to dim some time after the last active user interaction.Most useful for handheld devices, allowing OS to preserve battery life in most efficient ways. Does nothing on non-handheld devices.sleepTimeout is measured in seconds. The default value varies from platform to platform, generally being non-zero.On mobile devices it would be useful to set sleepTimeout to [SleepTimeout.NeverSleep] for games using accelerometer as the main source of input. However, such games should allow screen dimming while in menu or paused. Currently you will only be able to set this property to one of the values predefined in [SleepTimeout] class. A get will return either one of the predefined values, or the actual number of seconds until screen gets dimmed, as specified in system preferences of the device.
打开Unity,新建一个空工程,然后Unity界面如下图
在工程中新建一个脚本,脚本可以命名为“SleepTest”,具体如下图
选中“SleepTest”脚本,双击脚本或者右键“Open C# Project”,打开脚本,具体如下图
在打开的脚本上进行代码编辑,首先设置一个cube变量,然后赋值,并设置屏幕neversleep,最后设置cube自转,具体代码及代码说明如下图
脚本编译正确后,回到Unity界面,在场景中新建一个“Cube”,然后把脚本“SleepTest”赋给“Cube”,具体如下图
保存场景,把工程Build安装到手机上,运行即可看到游戏不再自动黑屏了,具体如下图
到此,《Unity 入门操作 之 快速学会游戏运行不自动锁屏》讲解结束,谢谢
若帮到您,还请帮忙投票以帮助到更多的人;若有疑问,请留言