unity帧率问题
有时候unity打包出来后跟在Game视窗中看到的效果有很大的区别很有可能帧率的问题。
这个时候我们只需要用代码修改一下运行时的帧率即可
点击查看代码
void Awake()
{
Application.targetFrameRate = FPS;
}
也可以将它显示到你的Game视窗上,看一下具体的效果
点击查看代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace MyBaseFunc
{
//显示当前 Update() 刷新帧率
public class Fps : MonoBehaviour
{
//因为设置了帧率同屏幕刷新频率,故这里的设置只在编辑模式下有效。
public const int FPS = 60;
[SerializeField]
[Tooltip("窗口内打印帧率")]
bool m_showFps = false;
//
float m_waitSec = 1f;
float m_addTime;
int m_frames = 0;
public static float RealFPS { get; private set; } = FPS;
void Awake()
{
Application.targetFrameRate = FPS;
}
void Update()
{
m_frames++;
m_addTime += Time.deltaTime;
if (m_addTime > m_waitSec)
{
RealFPS = m_frames / m_addTime;
m_frames = 0;
m_addTime = 0;
}
}
#if UNITY_EDITOR
void OnGUI()
{
if (m_showFps)
{
GUI.skin.label.fontSize=30;
GUI.skin.label.normal.textColor=Color.red;
GUILayout.Label("帧率:" + Application.targetFrameRate + " - " + RealFPS.ToString());
}
}
#endif
}//end class
}//end namespace
#if UNITY_EDITOR
#endif

浙公网安备 33010602011771号