当前位置:网站首页>How unity runs code every few frames

How unity runs code every few frames

2022-06-24 05:09:00 LittleU

Actually in unity in , There is a method to record the number of frames the game is running , Why should I do a function that runs a certain code every few frames ? as a result of , If in update Running in is a waste of resources , Put it in FixedUpdate Run in , Then we need to modify step time, But elsewhere fixedUpdate It's changed , So I want to solve this problem by running a code block every few frames , But it took a long time , They teach you how to look at the frame number , therefore , I went to look through API manual , Finally found a way , This method records the number of frames the game runs from the beginning of the game . Until the game completely exits .

Time.frameCount

This method returns a int Type of shaping , The function prototype is as follows :

public static int frameCount { get; }

So I can pass every 5 Frame to run a piece of code :

 if (Time.frameCount % 5 == 0)
        {
          // Executed code ...
        }
原网站

版权声明
本文为[LittleU]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/08/20210823204536316j.html