Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 paulvincentphillips · Oct 19, 2016 at 06:31 PM · getkeydownspacebarleftmouseclick

Unity not recognising space bar and left click

Hi all!

Currently making a simple first game in Unity. When the user uses a key, the character should jump (2D game btw). However, the space bar and left click are not registering. When I use anyKeyDown it detects every other key I've tried. The space bar, when used, interacts with Unity instead of the game ie. opens a drop down menu in the game window. Mouse click does something along the same lines. Same happens when use Input.GetKeyDown(KeyCode.Space) and Input.GetMouseButtonDown(0), respectively.

void Update() { if(Input.anyKeyDown) { didFlap = true; } }

Thanks in advance!

Comment
Add comment · Show 2
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 Zitoox · Oct 19, 2016 at 08:46 PM 0
Share

Pretty strange. I know this is a stupid question, but did you clicked on the play button? And if possible, show us the script. $$anonymous$$aybe you are missing something.

avatar image TreyH · Oct 20, 2016 at 01:35 PM 0
Share

Where are you calling to check those inputs?

5 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by danivdwerf · Oct 19, 2016 at 06:45 PM

can you show us the script that you use?

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 paulvincentphillips · Oct 19, 2016 at 09:03 PM

using UnityEngine; using System.Collections;

public class BirdMovement : MonoBehaviour {

 Vector3 velocity = Vector3.zero;
 public Vector3 gravity;
 public Vector3 flapVelocity;
 public float maxSpeed = 5f;

 bool didFlap = false;

 // Use this for initialization
 void Start () {
 
 }

 // Do Graphic & Input updates here
 void Update() {
     if(Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButtonDown(0) ) {
         didFlap = true;
     }
 }
 
 // Do physics engine updates here
 void FixedUpdate () {
     velocity += gravity * Time.deltaTime;

     if(didFlap == true) {
         didFlap = false;
         velocity += flapVelocity;
     }

     velocity = Vector3.ClampMagnitude(velocity, maxSpeed);

     transform.position += velocity * Time.deltaTime;

     float angle = 0;
     if (velocity.y < 0) {
         angle = Mathf.Lerp(0, -90, -velocity.y / maxSpeed);
     }

     transform.rotation = Quaternion.Euler(0, 0, angle);
 }

}

For context: Flappy Bird clone

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 danivdwerf · Oct 19, 2016 at 10:35 PM 0
Share

@paulvincentphillips this may sound stupid, but did you try clicking on the actual game window before pressing the button?

avatar image paulvincentphillips danivdwerf · Oct 20, 2016 at 01:10 PM 0
Share

Yeah, play button is pressed. It's as if game runs and when I press space it'll open a pop up window and interrupt the game. Same if I click but it might interact with a sprite etc.

avatar image danivdwerf paulvincentphillips · Oct 21, 2016 at 07:32 AM 0
Share

no I mean, do you first click on the actual window where the games is, just on the window. It might be focused on editor still.

avatar image
0

Answer by trollent1113 · Oct 19, 2016 at 09:03 PM

if you go to edit---project settings---input it should tell you what you can type for space or ''jump''. if you need a simple 2d jump script see if this works

 public float jumpForce = 7.5f;

 void Start()
 {

 }

 void Update()
 {
     if (Input.GetKeyDown(KeyCode.Space))
     {
         GetComponent<Rigidbody2D>().velocity = new Vector2(GetComponent<Rigidbody2D>().velocity.x, jumpForce);
     }
 }


this is not tested btw. Hope it helps @ paulvincentphillips

Comment
Add comment · Show 1 · 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 paulvincentphillips · Oct 20, 2016 at 01:08 PM 0
Share

Thanks. Will test this evening

avatar image
0

Answer by PeteD · Oct 20, 2016 at 01:49 PM

Interesting. The behaviour you describe is present if you have toggled sticky keys to be on. In which case pressing space will act as a menu open instead of a standard key press.

If you are on windows check under accessibility, that you don't have sticky keys or any of those settings enabled. Not sure where this setting lives on a mac.

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 RecklessTechguy · Aug 31, 2020 at 10:37 PM

I am having the same issue with using space button, though I do not get a menu action from using it. Have not tested this with the left mouse so far. If you find a fix I would love to know.

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

8 People are following this question.

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

Related Questions

check if spacebar was pressed two times 2 Answers

Change a Variable on Key Down 5 Answers

Check if button is pressed 1 Answer

KeyCode.Enter 2 Answers

How can I have multiple shoot buttons? 1 Answer


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