指示游戏尝试以指定的帧率渲染。
默认的 targetFrameRate
是一个特殊值 -1,表示游戏应以平台的默认帧率渲染。此默认速率取决于平台:
- 在独立平台上,默认的帧率是可实现的最大帧率。
- 在移动平台上,由于需要节省电池电量,默认的帧率小于可达到的最大帧率。移动平台上的默认帧率通常为每秒 30 帧。
- 在 WebGL 上,默认值允许浏览器选择帧率来匹配其渲染循环时序,这通常会产生最平滑的效果。只有当您想要限制 WebGL 上的 CPU 使用率时,才建议使用非默认值。
- 使用 VR 时,Unity 将使用 SDK 指定的目标帧率并忽略游戏指定的值。
设置 targetFrameRate
并不保证将实现帧率。由于平台规格不同,帧率可能会出现波动,或者由于计算机速度太慢,游戏可能无法达到帧率。
此外,如果设置了 QualitySettings.vSyncCount 属性,将忽略 /targetFrameRate/,而游戏将使用 vSyncCount 和平台的默认渲染率来确定目标帧率。例如,如果平台的默认渲染速率为每秒 60 帧且 vSyncCount 设置为 2,则游戏将以每秒 30 帧为目标。
在编辑器中,targetFrameRate
仅影响 Game 窗口。它在其他编辑器窗口中不起作用。
using UnityEngine;
public class Example { void Start() { // Make the game run as fast as possible Application.targetFrameRate = 300; } }
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.