(MHF 개발일지) 캐릭터 액션 기능 구현4
보스 투사체2(바위)의 크기와 토크가 매 프레임마다 증가하는 설정대로라면, 사용하는 PC, 스마트폰의 CPU 사양에 따라 FPS(frame per second) 가 달라지므로 투사체의 크기도 달라지게 되는 문제가 있다. 그래서 FPS를 미리 고정해두기로 하였다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// C#코드, FPSCounter.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FrameCounter : MonoBehaviour
{
private float deltaTime = 0f;
[SerializeField, Range(1, 100)]
private int size = 25;
[SerializeField]
private Color color = Color.green;
private int fpsMode = 0;
public bool isShow;
private void Awake()
{
Application.targetFrameRate = 60;
}
//Update is called once per frame
private void Update()
{
deltaTime += (Time.unscaledDeltaTime - deltaTime) * 0.1f;
if (Input.GetKeyDown(KeyCode.F1))
{
isShow = !isShow;
}
if (Input.GetKeyDown(KeyCode.Alpha0))
{
if (fpsMode == 0)
Application.targetFrameRate = 30;
if (fpsMode == 1)
Application.targetFrameRate = 45;
if (fpsMode == 2)
Application.targetFrameRate = 60;
if (fpsMode == 3)
Application.targetFrameRate = 120;
fpsMode = (fpsMode+1) % 4;
}
}
private void OnGUI()
{
if (isShow)
{
GUIStyle style = new GUIStyle();
int w = Screen.width, h = Screen.height;
Rect rect = new Rect(30, 30, Screen.width, Screen.height);
style.alignment = TextAnchor.UpperLeft;
style.fontSize = h * 4 / 100;
style.normal.textColor = color;
float ms = deltaTime * 1000f;
float fps = 1.0f / deltaTime;
string text = string.Format("{0:0.} FPS ({1:0.0} ms)", fps, ms);
GUI.Label(rect, text, style);
}
}
}
이 기사는 저작권자의 CC BY 4.0 라이센스를 따릅니다.

