반응형
아무 게임오브젝트에 해당 스크립트를 붙이면 Debug가 출력 될 때 화면에 똑같이 출력해준다.
에디터에서는 필요없겠지만 기기에서 테스트할 때 편리하다.
using System.Collections;
using UnityEngine;
public class DebugToScreen : MonoBehaviour {
string myLog;
Queue myLogQueue = new Queue ();
void OnEnable () {
Application.logMessageReceived += HandleLog;
}
void OnDisable () {
Application.logMessageReceived -= HandleLog;
}
void HandleLog (string logString, string stackTrace, LogType type) {
myLog = logString;
string newString = "\n [" + type + "] : " + myLog;
myLogQueue.Enqueue (newString);
if (type == LogType.Exception) {
newString = "\n" + stackTrace;
myLogQueue.Enqueue (newString);
}
myLog = string.Empty;
foreach (string mylog in myLogQueue) {
myLog += mylog;
}
}
void OnGUI () {
GUILayout.Label (myLog);
}
}
반응형
'unity C#' 카테고리의 다른 글
| [Unity] 로컬파일 불러오기(안드로이드, mac, pc) (0) | 2019.06.18 |
|---|---|
| [Unity] UI Sprite Image 가장자리 Antialiasing 설정 (0) | 2019.06.03 |
| [Unity] Face Tracking을 이용한 화면 로테이션 (1) | 2019.05.24 |
| [Unity] ScrollRect 에 붙은 Button처리하기 (0) | 2019.05.23 |
| [Unity] unity loading bar 구현 (0) | 2019.05.16 |