So, I'm trying to load the next scene by pressing a button on screen. Earlier, I had it so when the user presses enter, the scene will load, but after realizing that wouldn't work too smoothly on iPads, I decided to switch to buttons. But the button method makes the next scene nearly two minutes to load, while the press Enter method was nearly instantaneous. Anyone have any idea why that is?
//Press Enter method
if (Input.GetKeyDown(KeyCode.Tab))
{
//If there's a space in the word, display a message and don't progress
if (input.text.Contains(" "))
warningWord.text = "Words cannot contain spaces!";
//If the word is valid...
else if (!string.IsNullOrEmpty(input.text))
{
//Display no error message
warningWord.text = ("");
//Set the string to the inputfield's contents
wordToSpell = input.text;
//Show the list of already typed words
typedWords.text = typedWords.text + "\n" + input.text;
//clear the input field
input.text = "";
//Set the word to all caps in order to keep it simple
wordToSpell = wordToSpell.ToUpper();
//Add the word to the list of words
wordList.Add(wordToSpell);
}
}
//If the Return (Enter) key is pressed...
if (Input.GetKeyDown(KeyCode.Return))
{
//If the user hasn't entered any words, display a message and don't progress
if (wordList.Count == 0)
warningWord.text = ("You haven't entered any words!");
//If the user has not selected a difficulty, display a message and don't progress
if (!easy.isOn && !medium.isOn && !hard.isOn)
warningDifficulty.text = ("You haven't selected a difficulty!");
//If a difficulty is selected and there are words that have been entered...
if ((easy.isOn || medium.isOn || hard.isOn) && wordList.Count > 0)
{
//Set the backup list to the real list
backupList = new List<string>(wordList);
//Set the difficulties depending on the selected bubbles
if (easy.isOn)
PlayerPrefs.SetString("difficulty", "easy");
else if (medium.isOn)
PlayerPrefs.SetString("difficulty", "medium");
else if (hard.isOn)
PlayerPrefs.SetString("difficulty", "hard");
//Make the canvas invisible as to hide the text boxes in the later scenes
canvas.gameObject.SetActive(false);
//Load the game
SceneManager.LoadScene(1);
}
}
//Button method
void Update()
{
//As long as a difficulty is selected, don't display an error message
if (easy.isOn || medium.isOn || hard.isOn)
warningDifficulty.text = "";
//If the enter word button is pressed...
enterWord.onClick.AddListener(EnterButton);
//If the start game button is pressed...
startGame.onClick.AddListener(StartButton);
}
void EnterButton()
{
//If there's a space in the word, display a message and don't progress
if (input.text.Contains(" "))
warningWord.text = "Words cannot contain spaces!";
//If the word is valid...
else if (!string.IsNullOrEmpty(input.text))
{
//Display no error message
warningWord.text = ("");
//Set the string to the inputfield's contents
wordToSpell = input.text;
//Show the list of already typed words
typedWords.text = typedWords.text + "\n" + input.text;
//clear the input field
input.text = "";
//Set the word to all caps in order to keep it simple
wordToSpell = wordToSpell.ToUpper();
//Add the word to the list of words
wordList.Add(wordToSpell);
}
}
void StartButton()
{
//If the user hasn't entered any words, display a message and don't progress
if (wordList.Count == 0)
warningWord.text = ("You haven't entered any words!");
//If the user has not selected a difficulty, display a message and don't progress
if (!easy.isOn && !medium.isOn && !hard.isOn)
warningDifficulty.text = ("You haven't selected a difficulty!");
//If a difficulty is selected and there are words that have been entered...
if ((easy.isOn || medium.isOn || hard.isOn) && wordList.Count > 0)
{
//Set the backup list to the real list
backupList = new List<string>(wordList);
//Set the difficulties depending on the selected bubbles
if (easy.isOn)
PlayerPrefs.SetString("difficulty", "easy");
else if (medium.isOn)
PlayerPrefs.SetString("difficulty", "medium");
else if (hard.isOn)
PlayerPrefs.SetString("difficulty", "hard");
//Make the canvas invisible as to hide the text boxes in the later scenes
canvas.gameObject.SetActive(false);
//Load the game
SceneManager.LoadScene(1);
}
}