[Unity3d] View and set the number of game frames fps

Source: Internet
Author: User

FPS is an important indicator of game performance, Unity is a cross-platform engine tool, so there is no uniform qualification of his frame rate.
In the PC platform, generally the higher the better, the higher the FPS, the more smooth the game.
In the mobile phone platform, the general flow index of 60 frames, can run to 60 frames, is very smooth experience, and then a high difference is very small, and the number of frames is too high, will consume CPU and GPU, will lead to heat and power consumption.
1.unity3d How to set the frame number FPS
After 3.5 versions, the application.targetframerate can be set directly. You can modify the script directly.
Using unityengine;using System.Collections;
public class Setfps:monobehaviour {void Awake () {Application.targetframerate = 60;//here limit 60 frames}}
The default parameter is-1, which will render the game as fast as possible on all platforms, up to 50~60 frames on the web platform.
It is important to note thatUnder Edit/project setting/qualitysettings, if VSync is set, the Targetframerate setting will be invalid. The two are conflicting relations. See the following script for details, the latest address:
Http://docs.unity3d.com/Documentation/ScriptReference/Application-targetFrameRate.html

2. How to view the current frame number fps?
Using unityengine;using System.Collections; [System.Reflection.Obfuscation (Exclude = True)]public class Debugscreen:monobehaviour {//Use this for INITIALIZATIONVO    ID Start () {}//Update is called once per framevoid update () {Updatetick ();}    void Ongui () {drawfps ();        private void Drawfps () {if (Mlastfps >) {gui.color = new color (0, 1, 0);        } else if (Mlastfps > +) {gui.color = new color (1, 1, 0);        } else {gui.color = new color (1.0f, 0, 0); } GUI.                Label (New Rect (.), "FPS:" + mlastfps);    } private Long mframecount = 0;    Private long mlastframetime = 0;    static long mlastfps = 0;            private void Updatetick () {if (true) {mframecount++;            Long ncurtime = Ticktomillisec (System.DateTime.Now.Ticks); if (Mlastframetime = = 0) {Mlastframetime = Ticktomillisec (System.DateTime.Now.Ticks); } if ((Ncurtime-mlastframetime) >=) {Long fps = (long) (Mframecount * 1.0f                /((ncurtime-mlastframetime)/1000.0f));                Mlastfps = fps;                Mframecount = 0;            Mlastframetime = Ncurtime;    }}} public static long ticktomillisec (long tick) {return tick/(10 * 1000); }}


[Unity3d] View and set the number of game frames fps

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.