- Home /
How to make a inputfield ignore if it's normal or capital letters.
Is it possible to make it so I can answer with both capital letters and normal letters. That If you Wright the answer like this "ArMy oF tWo" it just as right as "army of two" Her is the script for the InputField. Thanks in Advance :)--------------------- using UnityEngine; using System.Collections; using UnityEngine.UI; using UnityEngine.SceneManagement;
public class ArmyOfTwo: MonoBehaviour {
private string gameName;
private int countGuess;
[SerializeField]
private InputField input;
[SerializeField]
private Text text;
void Awake(){
gameName = "army of two";
text.text = "Guess The Name Of The Game";
}
public void GetInput(string guess){
CompareGuesses(guess);
input.text = "";
}
public void CompareGuesses (string guess){
if (guess == gameName) {
text.text = "You Guessed Correctly";
SceneManager.LoadScene("Level 1");
} else if (guess != gameName) {
text.text = "Wrong!";
} else if (guess != gameName) {
text.text = "Wrong!";
}
}
}
Answer by renem · Aug 03, 2016 at 01:20 PM
Hi, did you tried to convert your string to lowercase with the toLower() function? Like following:
public void CompareGuesses (string guess){
if (guess.ToLower() == gameName.ToLower()) {
text.text = "You Guessed Correctly";
SceneManager.LoadScene("Level 1");
} else if (guess.ToLower() != gameName.ToLower()) {
text.text = "Wrong!";
} else if (guess.ToLower() != gameName.ToLower()) {
text.text = "Wrong!";
}
}
Answer by Arkaid · Aug 03, 2016 at 08:24 AM
convert everything to lowercase or uppercase before comparing
string test1 = "HelLLo WOrlD"
string test2 = "hELLO woRLd"
bool equals = test1.ToLower() == test2.ToLower()
I'm pretty new to scripting, could you please show me how it's done in the script I have added?
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Making an image appear from a different script 0 Answers
Change Scene by answering right 3 Answers