Disable GUI.Textfield after a GUI button is pressed?
Hello there, I was wondering if it is possible to disable the textfield just like you disable the GUI.button? Any help would do me a huge favour!
var isVisible = true;
function OnGUI() {
if(isVisible ){
bestPlayer = GUI.TextField (Rect (600,120,200,50),bestPlayer, 25);
isVisible = false;
}
PlayerPrefs.SetString("PlayerName",bestPlayer);
}
I tried the above code but this doesn't even make the textfield appear.
What did you mean by "disable " ? just hide it ? you can do it with a boolean
where did you switch the value of isVisible ? because with this code the textfield should not be visible. Are you sure that your isVisible boolean is'nt set to true somewhere else ?
Answer by GluedBrain · Apr 18, 2013 at 04:28 PM
var isVisible = true;
function OnGUI() {
if(isVisible ){
bestPlayer = GUI.TextField (Rect (600,120,200,50),bestPlayer, 25);
PlayerPrefs.SetString("PlayerName",bestPlayer);
if (Event.current.keyCode == KeyCode.Return) {
isVisible =false;
}
}
This should disable the gui.textarea once you click "enter" button
Your answer
Follow this Question
Related Questions
Display rigidbody speed to a world space canvas text 2 Answers
Uncommon Text behaviour 0 Answers
GUI.Label if close to object 0 Answers
How to use individual textures as font in GUI? 0 Answers
How do I start with text inactive? 1 Answer