hey guys , im making hangman game. i have images of hangman parts and a background save donto my desktop , how would i go about building the GUI , like say if i get a letter wrong then it draws a head etc? here is my code
public string words;
private int lifes = 7;
private string userInput = “”;
private string guessedWord = “”;
public string wordChosen = “”;
private void Start()
{
wordChosen = words[Random.Range(0, words.Length)];
guessedWord = new string(“-”[0] , wordChosen.Length);
}
private void OnGui()
{
if (lifes > 0 && guessedWord != wordChosen)
{
GUILayout.Label(lifes.ToString());
GUILayout.Box(guessedWord);
userInput = GUILayout.TextField(userInput , GUILayout.Width(200));
if(GUILayout.Button(“Try”))
{
if (userInput.Length == 1)
CheckChar(userInput[0]);
else if (userInput.Length > 1)
{
if (wordChosen == userInput)
guessedWord = userInput;
}
else
print("Please Enter One Character At A Time :)");
userInput = "";
}
}
else
{
if (lifes > 0)
GUILayout.Box("Congratulations! You Win!");
else
GUILayout.Box(" Awww You Lose :(");
}
}
private void CheckChar(char c)
{
bool charExists = false;
for(int x = 0; x < wordChosen.Length; x++)
{
if (wordChosen[x] == c)
{
charExists = true;
string temp = guessedWord.Substring(0 , x);
guessedWord = temp + c.ToString() + guessedWord.Substring(x + 1, guessedWord.Length - x - 1);
}
}
if(!charExists)
lifes --;
}