Advertisement
infinite_ammo

CharBuffer.cs

Mar 8th, 2013
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.14 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class CharBuffer : MonoBehaviour
  5. {
  6.     public string buffer;
  7.  
  8.     private const int size = 32;
  9.  
  10.     void Update()
  11.     {
  12.         for (KeyCode keyCode = KeyCode.A; keyCode <= KeyCode.Z; keyCode++)
  13.         {
  14.             if (Input.GetKeyDown(keyCode))
  15.             {
  16.                 if (buffer.Length >= size)
  17.                     buffer = buffer.Substring(1, buffer.Length-1);
  18.                
  19.                 buffer += ((char)(((int)keyCode - (int)KeyCode.A) + (int)('A')));
  20.             }
  21.         }
  22.  
  23.         for (KeyCode keyCode = KeyCode.Alpha0; keyCode <= KeyCode.Alpha9; keyCode++)
  24.         {
  25.             if (Input.GetKeyDown(keyCode))
  26.             {
  27.                 if (buffer.Length >= size)
  28.                     buffer = buffer.Substring(1, buffer.Length - 1);
  29.                
  30.                 buffer += "" + ((int)keyCode - (int)KeyCode.Alpha0);
  31.             }
  32.         }
  33.     }
  34.  
  35.     public bool Contains(string match)
  36.     {
  37.         if (buffer.Contains(match.ToUpper()))
  38.         {
  39.             buffer = "";
  40.             return true;
  41.         }
  42.         return false;
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement