Object not appearing after inputted the correct answer,Object not activating even after inputting answer
Pardon my English in advance.
I'm making a game where when the player input the correct answer, the door will appear, sadly that doesnt happen.
The code for the GameController (the password) :
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class GameController : MonoBehaviour {
public string answer;
public InputField mainInputField;
public static bool GotAnswer;
void Update (){
answer = mainInputField.text;
if (answer == "Tunku Abdul Rahman" && Input.GetKey(KeyCode.Return)) {
Debug.Log ("Correct");
GotAnswer = true;
}
}
}
And here is my ExitHider for the door :
using UnityEngine; using System.Collections;
public class ExitHider : MonoBehaviour { GameObject Exit;
void Start () {
Exit = GameObject.Find ("Exit");
Exit.SetActive (false);
}
// Update is called once per frame
void Update ()
{
if (GameController.GotAnswer == false)
{
Exit.SetActive (false);
}
if (GameController.GotAnswer == true)
{
Exit.SetActive (true);
}
}
}
I cannot trace where did I go wrong, the input did indeed work since I could see the debug on the console, but the door still wont appear.
Any help would be appreciated.,Im making a code where the player needs to input an answer to make a door appear, sadly even after the input and pressing enter, the door doesn't appear. On console I can see that the input is indeed working.
The GameController :
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class GameController : MonoBehaviour {
public string answer;
public InputField mainInputField;
public static bool GotAnswer;
void Update (){
answer = mainInputField.text;
if (answer == "Tunku Abdul Rahman" && Input.GetKey(KeyCode.Return)) {
Debug.Log ("Correct");
GotAnswer = true;
}
}
}
and heres the code for the ExitHider
using UnityEngine; using System.Collections;
public class ExitHider : MonoBehaviour { GameObject Exit;
void Start () {
Exit = GameObject.Find ("Exit");
Exit.SetActive (false);
}
// Update is called once per frame
void Update ()
{
if (GameController.GotAnswer == false)
{
Exit.SetActive (false);
}
if (GameController.GotAnswer == true)
{
Exit.SetActive (true);
}
}
}
I don't recieved any errors so I cannot trace where I may got wrong. Any help would be appreciated.
Pardon my English.
Your answer
Follow this Question
Related Questions
Making an image appear 0 Answers
Detecting if is currently entering text on any component. 0 Answers
Control UI Input Field entirely with code? 1 Answer
Use InputField to be a search bar with a ScrollRect 0 Answers
Autocomplete Search (Search Suggestion) 5 Answers