- Home /
(JAVASCRIPT)I have a amnesia style note script, and I need help displaying the words
private var drawGUI = false; function update() { if (drawGUI == true && Input.GetKeyDown(KeyCode.E)) { GUI.Box (Rect (Screen.width/2-60, 450, 120, 22), "Go to the factory"); } }
function OnTriggerEnter (theCollider : Collider) { if (theCollider.tag == "Player") { drawGUI = true; }
} function OnTriggerExit(theCollider : Collider) { if (theCollider.tag == "Player") { drawGUI = false; } } function OnGUI() { if (drawGUI == true) { GUI.Box (Rect (Screen.width/2-60, 400, 120, 22), "Press E to read"); } }
The Code piece "if (drawGUI == true && Input.GetKeyDown(KeyCode.E)) { GUI.Box (Rect (Screen.width/2-60, 450, 120, 22), "Go to the factory"); }" Is giving me trouble. I think it has something to do with the (Keycode.E).
maybe you should change it to getkey ins$$anonymous$$d of getkeydown. now it shows if you press E but disappears immediately after your key is down, if you use getkey ($$anonymous$$eyCode.E) and you hold E the text wil also stay, but i'm not very sure of this without testing it my self.
(ps: i prefer using input.getbutton ("jump, fire use, whatever you assigned") so you can always change your keys later without changing your scripts ( and people wil later on can change it in the game options if you want) you can assign your keys in unity under: menubar/edit/project settings/input
Please format your code and clarify what your actual problem is.
Your answer
Follow this Question
Related Questions
problem not playing animation on keyDown 2 Answers
swap between two items 1 Answer
Calling GetKeyDown for C# instead of Javascript 2 Answers
Setting Scroll View Width GUILayout 1 Answer
Can someone help me fix my Javascript for Flickering Light? 6 Answers