Skip to content

Instantly share code, notes, and snippets.

@ThomasAunvik
Created August 9, 2017 20:08
Show Gist options
  • Save ThomasAunvik/ad9af27e218c2ed43215ad6c63a1e373 to your computer and use it in GitHub Desktop.
Save ThomasAunvik/ad9af27e218c2ed43215ad6c63a1e373 to your computer and use it in GitHub Desktop.
/// <summary>
/// Will keep the number of key taps that have been pressed.
/// </summary>
private int keyTaps = 0, currentXNames = 0, currentYNames = 1;
/// <summary>
/// Will launch a method that will write the word "Code" to the computer screen.
/// </summary>
void KeyTapped() {
if(!ComputerMenu.isMenuOpen) { //TODO add ifInMenu equals false.
if(!(currentYNames >= computerSettings.yNames && currentXNames == computerSettings.xNames)) {
WriteText(!(keyTaps < currentYNames * computerSettings.xNames));
} else if(Input.GetKeyDown(KeyCode.Return)) CompleteCode();
}
}
/// <summary>
/// Writes the text "Code" either in a new line or not
/// </summary>
/// <param name="newLine">"Code" should be placed on a new line?</param>
void WriteText(bool newLine) {
string currentText = TextObject.GetComponent<TextMesh>().text;
if(!newLine) {
currentText = currentText + "Code";
currentXNames++;
} else {
currentText = currentText + "\nCode";
currentYNames++;
currentXNames = 1;
}
keyTaps++;
TextObject.GetComponent<TextMesh>().text = currentText;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment