- Home /
Question is off-topic or not relevant
Database for a hangman game
Hello, I am practicing in Unity by making a hangman game. Right now my name has only one word so I can test the code. The only way I figured out to code the word guessing correctly is by adding a lot of "IFS", which I think will be tiring and problably the worst way. Below is the code:
var word : string; var esp1 : string; var esp2 : string; var esp3 : string; var esp4 : string; var esp5 : string; var points : float;
function Update () {
if word = "HELLO" {
esp1 == "H";
esp2 == "E";
esp3 == "L";
esp4 == "L";
esp5 == "O";
}
if LetterGuess.letterguess = "H" {
Letter1.renderer.enabled = true;
points = points + 10;
} else {
points = points - 10;
head.renderer.enabled = true;
}
}
This code is just an idea (I know, it is full of errors - think of it as a pseudocode). What I'm trying to express is that if the random word is "HELLO", the five letter variables will be H-E-L-L-O, and if the letter guessed is any of the included in the word, the player will win 10 points and the 3D letter will be visible in the game. If it is wrong, the player will lose 10 points and the head of the stickman will be visible. However, I don't want to fill the code with "IFS", so I was wondering if there is any way that I can create some sort of database (with javascript) with the letters of the words and simply compare them to the guessed letter and do the same commands that I coded.
Thanks in advance.
Not strictly a Unity question, this is general program$$anonymous$$g. You should look into Arrays and substrings (String methods)
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Mouse scroller problem 1 Answer
Shader forge Toggle 3 Answers
Making an animation play when you press down 2 keys 1 Answer
Sims like building script, picture and webplayer included 2 Answers