- Home /
GetKeyUp Problem
I'm trying to run a simple code that will print something when I press the Space Bar. I'm very new to coding, so I apologize if the answer is simple and I overlooked it. The problem is that nothing is being printed in the console when I press the Space Bar.
var MenuScreen : int = 0;
if (MenuScreen == 0) {
if (Input.GetKeyUp(KeyCode.Space)){
print ("Bacon");
}
}
Any help is greatly appreciated! :)
AH, Sorry. The problem is that nothing is being printed into the console whenever I press the space bar.
Use unity's method for displaying test (i.e Debug.Log("SO$$anonymous$$ETHING");)
here are some more visual displays to console Debug
Answer by king_ · Jul 24, 2014 at 02:24 PM
void Update()
{
if(Input.GetKeyUp(KeyCode.Space) && MenuScreen==0)
print("Bacon");
}
This is incorrect as well. You need to use Debug.Log for it to show in the console.
Actually this worked perfectly fine. I got exactly the results I needed for this. Thanks! I needed to put this into JavaScript though, but I managed to do that pretty easily. I do believe that the problem was that I didn't have a function update. Thanks everyone though!
This proves that only the people here on the answers site are only looking for answers with code , they are even too lazy to think about it , just copy pastin in there project , my answer is exaclty as this one , answered 5 hours before this one
Answer by xtron32 · Jul 24, 2014 at 12:36 AM
Debug.Log and Debug.LogError are the main log functions that you should be using, not print.
Also, make sure your script is actually a component of a gameobject in the scene.
If that doesn't solve your issue, check to make sure there are no compiler errors.
Thanks.
Answer by kilian277 · Jul 24, 2014 at 10:03 AM
The code where you check if the spacebar is pressed , is it placed within the update method of your script ? It will likely not be registered by the script because it maybe only run once.
Try adding it to your update method/ function in the case of javascript
And also use
Debug.Log("BACON");
if you want to output something to the console
Your answer
Follow this Question
Related Questions
GetKeyUp fires twice?!? 3 Answers
Mute audio with GetKeyDown 0 Answers
Dialogue with GetKey - Codes 1 Answer
OnGUI: += and -= operations problem 2 Answers
I need help with Jump animations 0 Answers