ShovelingLife
A Game Programmer
ShovelingLife
전체 방문자
오늘
어제
  • 분류 전체보기 (1110)
    • 그래픽스 (57)
      • 공통 (19)
      • 수학 물리 (22)
      • OpenGL & Vulkan (1)
      • DirectX (14)
    • 게임엔진 (190)
      • Unreal (69)
      • Unity (110)
      • Cocos2D-X (3)
      • 개인 플젝 (8)
    • 코딩테스트 (221)
      • 공통 (7)
      • 프로그래머스 (22)
      • 백준 (162)
      • LeetCode (19)
      • HackerRank (2)
      • 코딩테스트 알고리즘 (8)
    • CS (242)
      • 공통 (21)
      • 네트워크 (45)
      • OS & 하드웨어 (60)
      • 자료구조 & 알고리즘 (99)
      • 디자인패턴 (6)
      • UML (4)
      • 데이터베이스 (7)
    • 프로그래밍 언어 (376)
      • C++ (168)
      • C# (96)
      • Java (11)
      • Python (36)
      • SQL (44)
      • JavaScript (9)
      • React (7)
    • 그 외 (3)
      • Math (7)
      • 일상 (5)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

  • Source Code 좌측 상단에 복사 버튼 추가 완료
  • 언리얼 엔진 C++ 빌드시간 단축 꿀팁
  • 게임 업계 코딩테스트 관련
  • 1인칭 시점으로 써내려가는 글들

인기 글

태그

  • C
  • 그래픽스
  • 배열
  • 함수
  • 티스토리챌린지
  • 언리얼
  • 오블완
  • 포인터
  • python
  • 파이썬
  • 알고리즘
  • string
  • C++
  • Unity
  • 백준
  • SQL
  • 문자열
  • c#
  • 유니티
  • 클래스

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
ShovelingLife

A Game Programmer

게임엔진/Unity

[Unity] fps 로그창 GUI

2025. 12. 13. 23:05

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
    '게임엔진/Unity' 카테고리의 다른 글
    • [Unity] 커스텀 셰이더 UnityCG.cginc 헤더 파일 못찾는 이유
    • [Unity] ServiceLocatorManager > 구조 변경 / indexer, Type
    • [Unity] 애니메이션 마지막 프레임에서 이벤트 호출안되는 이유
    • [Unity] 로그 (Log) 출력시 스택 트레이스 (Stack Trace) 관리하기
    ShovelingLife
    ShovelingLife
    Main skill stack => Unity C# / Unreal C++ Studying Front / BackEnd, Java Python

    티스토리툴바