Version: 2021.2

Application.targetFrameRate

切换到手册
public static int targetFrameRate ;

描述

Specifies the frame rate at which Unity tries to render your game.

An integer.

The default value of Application.targetFrameRate is -1. In the default case, Unity uses the platform's default target frame rate.

Otherwise, targetFrameRate is a positive integer representing frames per second (fps). Unity tries to render your game at that frame rate.

Use targetFrameRate to control the frame rate of your game. For example, you might need to reduce your game's frame rate to make sure your game displays smoothly and consistently. You can also reduce your game's frame rate to conserve battery life on mobile devices and avoid overheating.

Note that platform and device capabilities affect the frame rate at runtime, so your game might not achieve the target frame rate.

targetFrameRate and vSyncCount

Both Application.targetFrameRate and QualitySettings.vSyncCount let you control your game's frame rate for smoother performance. targetFrameRate controls the frame rate by specifying the number of frames your game tries to render per second, whereas vSyncCount specifies the number of screen refreshes to allow between frames.

Mobile platforms ignore QualitySettings.vSyncCount. Use Application.targetFrameRate to control the frame rate on mobile platforms.

VR platforms ignore both QualitySettings.vSyncCount and Application.targetFrameRate. Instead, the VR SDK controls the frame rate.

On all other platforms, Unity ignores the value of targetFrameRate if you set vSyncCount. When you use vSyncCount, Unity calculates the target frame rate by dividing the platform's default target frame rate by the value of vSyncCount. For example, if the platform's default render rate is 60 fps and vSyncCount is 2, Unity tries to render the game at 30 frames per second.

Platform notes

Standalone platforms

On standalone platforms, the default frame rate is the maximum achievable frame rate. To use the platform's default frame rate, set Application.targetFrameRate to -1.

Mobile platforms

A mobile device's maximum achievable frame rate is the refresh rate of the screen. For example, a device with a refresh rate of 60 Hertz has a maximum achievable frame rate of 60 frames per second. To target the maximum achievable frame rate, set Application.targetFrameRate to the screen's refresh rate. Screen.currentResolution contains the screen's refresh rate.

To conserve battery power, the default frame rate on mobile platforms is lower than the maximum achievable frame rate. Usually, the default frame rate on mobile platforms is 30 fps. To target the default frame rate, set Application.targetFrameRate to -1.

To target a frame rate other than the maximum achievable frame rate or the platform default on mobile platforms, set Application.targetFrameRate to the screen's refresh rate divided by an integer. If the target frame rate is not a divisor of the screen refresh rate, the resulting frame rate is always lower than Application.targetFrameRate.

Note that mobile platforms ignore the QualitySettings.vSyncCount setting. Instead, you use the target frame rate to achieve the same effect as setting the vertical sync count. To do this, divide the screen's refresh rate by the number of vertical syncs you want to allow between frames, and set Application.targetFrameRate to this number.

For example, on a device with a screen refresh rate of 60 Hz, to allow: 1 vertical sync between frames, set targetFrameRate to 60. 2 vertical syncs between frames, set targetFrameRate to 30. 3 vertical syncs between frames, set targetFrameRate to 20. WebGL

By default, WebGL lets the browser choose a frame rate that matches its render loop timing. To use the browser's chosen frame rate, set Application.targetFrameRate to -1.

Usually, the browser's chosen frame rate gives the smoothest performance. You should only set a different target frame rate on WebGL if you want to throttle CPU usage.

VR

VR platforms ignore Application.targetFrameRate and QualitySettings.vSyncCount. Instead, the VR SDK controls the frame rate.

Unity Editor

In the Editor, Application.targetFrameRate affects only the Game View. It has no effect on other Editor windows.

See Also: QualitySettings.vSyncCount

using UnityEngine;

public class Example { void Start() { // Make the game run as fast as possible Application.targetFrameRate = 300; } }