Word guessing game
Hey guys, a massive unity beginner here. I am trying to finish my first c# game, and my idea is for the user to guess a word to advance to the next level.
Basically each level will have some sort of clue, lets say: "The opposite of light". The answer is obviously "Dark", so when the user enters that into an input field, the next level will load.
I followed a tutorial that did this but with numbers, but as far as i can tell, i cannot store normal characters (abc) in an "int". Do i use "char" instead? Basically i want to create a number guessing game, but with words instead, like a password guesser.
Any help appreciated, thanks :)
Answer by MaxGuernseyIII · Sep 14, 2017 at 04:52 PM
You use a string. As in...
string secretWord = "dark";
Unless you want to make them guess the case, in addition to the word, use ToUpper or ToLower. As in...
if (Equals(secretWord.ToLower(), textBox.text.ToLower())) GoToNextLevel();
Thank you for your answer, $$anonymous$$ax.
I am very new to Unity, so i dont really understand what you mean, or rather, how to implement it.
this is what i have so far:
using System.Collections; using UnityEngine; using UnityEngine.UI;
public class GameController : $$anonymous$$onoBehaviour {
private string secretWord = "dark";
public string guessWord;
public void GetInput(string guessWord) {
}
void CompareGuesses(string guessWord) {
if (guessWord == secretWord) {
Debug.Log ("Correct!");
} else if (guessWord != secretWord) {
Debug.Log ("Wrong!");
}
}
}