OnGUI에서 매 프레임마다 띄워준다
Application.targetFrameRate 로 현재 목표 fps를 불러오거나 지정할 수 있다
public class FPSDisplay : MonoBehaviour
{
public bool toggle = false;
private GUIStyle style;
private Rect rect;
private float deltaTime = 0.0f;
const float updateInterval = 0.5f;
private int frames = 0;
private float fps = 0.0f;
private float timeLeft;
private int curFrame;
void Awake()
{
int w = Screen.width, h = Screen.height;
style = new GUIStyle();
rect = new Rect(10, 10, w, h * 2 / 100);
style.alignment = TextAnchor.UpperLeft;
style.fontSize = h * 2 / 50;
style.normal.textColor = Color.green;
}
// fps
void Update()
{
timeLeft -= Time.deltaTime;
frames++;
// Update FPS display every updateInterval seconds
if (timeLeft <= 0.0f)
{
fps = frames / updateInterval;
frames = 0;
timeLeft = updateInterval;
}
}
void OnGUI()
{
if (!toggle)
return;
string text = string.Format("{0:0.} FPS", fps);
GUI.Label(rect, text, style);
}
}'게임엔진 > Unity' 카테고리의 다른 글
| [Unity] 커스텀 셰이더 UnityCG.cginc 헤더 파일 못찾는 이유 (0) | 2025.12.27 |
|---|---|
| [Unity] ServiceLocatorManager > 구조 변경 / indexer, Type (0) | 2025.11.30 |
| [Unity] 애니메이션 마지막 프레임에서 이벤트 호출안되는 이유 (0) | 2025.11.23 |
| [Unity] 로그 (Log) 출력시 스택 트레이스 (Stack Trace) 관리하기 (0) | 2025.10.07 |
| [Unity] PlayerInput을 활용한 캐릭터 움직이는 방법 (0) | 2025.08.04 |