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
2
Question by $$anonymous$$ · May 18, 2018 at 06:45 PM · inputmousecursormouseclickmouse position

Disable mouse input and cursor in game

Hello, I'd like to completely disable everything related to mouse input. My game should be controlled only via keyboard (GUI and gameplay).

So, how can I disable mouse input and cursor? I don't want to show cursor in whole game and as I said game should only use keyboard.

Thanks.

Comment
Add comment
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

3 Replies

· Add your reply
  • Sort: 
avatar image
7

Answer by Vicarian · May 18, 2018 at 07:07 PM

To disable mouse input, open the InputManager from Edit > Project Settings > Input. Remove the input entries with Mouse in their name. Expand Fire1 - Fire3 and remove the mouse buttons from these. To hide the cursor, use the statements:

 Cursor.lockState = CursorLockMode.locked;
 Cursor.visible = false;
Comment
Add comment · Show 7 · 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 $$anonymous$$ · May 18, 2018 at 07:57 PM 0
Share

I did what you suggested. Actually, it works partially. There is a problem with mouse clicks. In menu screens in my Event System uses first selected button. When I click mouse, button loses focus and I can't navigate thourgh buttons in menu.

Do you have a solution for it?

avatar image Temseii $$anonymous$$ · May 18, 2018 at 08:02 PM 1
Share

I'm not sure if there's a clean way of completely disabling it. One hack you could pull is to just set the focus back to the button when the mouse is clicked.

avatar image Vicarian Temseii · May 18, 2018 at 08:09 PM 1
Share

This will temporarily break your menu navigation, but try unchecking Send Navigation Events in the EventSystem, and see if the mouse button causes focus loss?

Show more comments
avatar image JPhilipp · Jan 14, 2020 at 03:55 PM 0
Share

For reference, it's CursorLock$$anonymous$$ode.Locked (with an upper-case L).

avatar image Vice_Grips · Sep 22, 2020 at 07:41 PM 0
Share

When I tried this it would either only work when my cursor is over the game view, or it would give me a compile error and say "'CursorLock$$anonymous$$ode' does not contain a definition for locked" Is there a library I have to import? I only have the defaults for when you make a new c# script.

Thanks in advanced :)

avatar image
1

Answer by Robdon · Feb 14, 2020 at 06:01 PM

A bit late, but I just found this as I was trying to do the same.

What I did was have a GO (named MouseDisable) with a UI Image on it that stretches across the whole screen, and has 'Raycast Target' ticked. Also, make the Color white, and with Alpha = 0. IE not visible.

Then when ever I change the Cursor.visible, I just enable/disable that GO, and it 'absorbs' all the mouse clicks.

So, something like:

 public void SetCursorVisible(bool vis) {
     Cursor.visible = vis;
     MouseDisable.SetActive(!vis);
 }

Worked fine for what I needed. HTHs.

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 duckquark · Apr 02, 2019 at 10:52 PM

Hey. I had a similar issue and this worked for me. If there's any mouse clicks it just goes back to the default selection.

If you stored your current selection in a variable you could always use that as a parameter: CatchMouseClicks(currentButton);

     // Update is called once per frame
     void Update () {
 
         if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1) || Input.GetMouseButtonDown(2))
         {
 
             CatchMouseClicks(defaultSelection);
 
         }
 
     }
 
 
     public void CatchMouseClicks(GameObject setSelection)
     {
 
         EventSystem.current.SetSelectedGameObject(setSelection);
 
     }
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 Arkhan · Aug 11, 2019 at 05:43 PM 0
Share

If you are using Color Tint to indicate selected objects, this causes a visual indication that you clicked even if you are running a game where the mouse is "disabled". It very quickly deselects and reselects the object.

I$$anonymous$$HO, not being able to have this new UI event system just ignore clicks is kinda dodgy. Has Unity not heard of keyboard driven games?

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

110 People are following this question.

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

Related Questions

Unity Web Player does not respond to mouse clicks 1 Answer

Mouse click is detected twice 1 Answer

EventSystem - detect any click NOT on object 1 Answer

mouse Input Instantiate 0 Answers

Map mouse click state to a Joystick button? 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