Advertisement
infinite_ammo

DebugConsole.cs

Mar 17th, 2013
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.79 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class DebugConsole : MonoBehaviour
  5. {
  6.  
  7.     private static string debugText = "Hello, world.\n";
  8.     private static bool consoleOn = false;
  9.     private static Vector2 scrollPosition;
  10.    
  11.     void Update()
  12.     {
  13.         if (Input.GetKeyDown(KeyCode.Tab))
  14.         {
  15.             consoleOn = !consoleOn;
  16.         }
  17.     }
  18.    
  19.     public void Log(string text)
  20.     {
  21.         debugText = text + "\n" + debugText;
  22.        
  23.         const int max = 1024;
  24.         if (debugText.Length > max)
  25.         {
  26.             debugText = debugText.Substring(0, max);
  27.         }
  28.     }
  29.    
  30.     void OnGUI()
  31.     {
  32.        
  33.         if (consoleOn)
  34.         {
  35.             scrollPosition = GUILayout.BeginScrollView (
  36.                 scrollPosition, GUILayout.Width (400), GUILayout.Height (100));
  37.    
  38.             GUILayout.Label (debugText);
  39.  
  40.             GUILayout.EndScrollView ();
  41.    
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement