Canvas없이 따로 없이 사용할 경우
Canvas에서 Text Componet를 사용해 임의의 위치에 배치할 경우
using UnityEngine;
using System.Collections;
public class FPSDisplay : MonoBehaviour
{
// [RequireComponent(typeof(Text))]
float deltaTime = 0.0f;
private Text m_Text;
private void Start()
{
m_Text = GetComponent<Text>();
}
void Update()
{
deltaTime += (Time.deltaTime - deltaTime) * 0.1f ;
float msec = deltaTime * 1000.0f;
float fps = 1.0f / deltaTime;
m_Text.text = string.Format("{0:0.0} ms ({1:0.} fps)", msec, fps);
}
void OnGUI()
{
int w = Screen.width, h = Screen.height;
GUIStyle style = new GUIStyle();
Rect rect = new Rect(0, 0, w, h * 2 / 100);
style.alignment = TextAnchor.UpperLeft;
style.fontSize = h * 2 / 100;
style.normal.textColor = new Color (0.0f, 0.0f, 0.5f, 1.0f);
float msec = deltaTime * 1000.0f;
float fps = 1.0f / deltaTime;
string text = string.Format("{0:0.0} ms ({1:0.} fps)", msec, fps);
GUI.Label(rect, text, style);
}
}
'Technical Report > Unity Scripts' 카테고리의 다른 글
Custom Inspectors and Scriptable Objects for UDIM materials (0) | 2018.02.10 |
---|---|
Texture2D.Encode (0) | 2017.08.17 |
Unity Attribute API (0) | 2017.07.26 |
Unity Shader Property API (0) | 2017.07.25 |
ColorSuite Keijiro (0) | 2016.08.29 |