Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Correen · Jul 23, 2014 at 11:59 PM · getkeyup

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! :)

Comment
Add comment · Show 8
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image kilian277 · Jul 24, 2014 at 12:05 AM 0
Share

and what is the problem ?

avatar image Correen · Jul 24, 2014 at 12:08 AM 0
Share

AH, Sorry. The problem is that nothing is being printed into the console whenever I press the space bar.

avatar image cdrandin · Jul 24, 2014 at 12:09 AM 0
Share

Use unity's method for displaying test (i.e Debug.Log("SO$$anonymous$$ETHING");)

here are some more visual displays to console Debug

avatar image Correen · Jul 24, 2014 at 12:11 AM 0
Share

Nothing is still being shown.

avatar image cdrandin · Jul 24, 2014 at 12:13 AM 0
Share

Is your script attached to an object in the scene?

Show more comments

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by king_ · Jul 24, 2014 at 02:24 PM

 void Update()
 {
   if(Input.GetKeyUp(KeyCode.Space) && MenuScreen==0)
     print("Bacon");
 }
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image xtron32 · Jul 24, 2014 at 05:20 PM 0
Share

This is incorrect as well. You need to use Debug.Log for it to show in the console.

avatar image Correen · Jul 24, 2014 at 07:11 PM 0
Share

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!

avatar image kilian277 · Jul 24, 2014 at 07:24 PM 0
Share

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

avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges