Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by UbiquitousStudio · Oct 06, 2016 at 12:19 AM · cursor

Cursor.visible not working?

Hello, I am curious as to why I can't figure this one out. I have one scene acting as a main menu. I need the cursor to show on start, this here says it would work...

https://docs.unity3d.com/ScriptReference/Cursor-visible.html

 void Start()
 {
     Cursor.visible = true;
 }

That doesn't work, so I tried something like this instead.

 public bool cursorOn;
 
 void Start()
 {
    cursorOn = true;
 }
 
 void Update()
 {
    if(cursorOn == true)
    {
        ShowCursor();
    }
    else if(cursorOn == false)
    {
        HideCursor();
    }
 }
 
 void ShowCursor
 {
     Cursor.visible = true;
     Cursor.lockState = CursorLockMode.None;
 }
 
 void HideCursor()
 {
     Cursor.visible = false;
     Cursor.lockState = CursorLockMode.Locked;
 }

Nothing I have tried after that has worked, so I am coming here to hopefully find it out. The only stuff I could find online was exactly what I tried, but it didn't work. It used to be so much easier Unity, why did you need to change this..?

Comment
Add comment · Show 4
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 Namey5 · Oct 06, 2016 at 09:39 AM 0
Share

How are you hiding the cursor to begin with? By default, the cursor should be visible.

avatar image UbiquitousStudio Namey5 · Oct 06, 2016 at 02:08 PM 0
Share

I'm not hiding the cursor, it is gone on default for me.

avatar image Namey5 UbiquitousStudio · Oct 06, 2016 at 11:52 PM 0
Share

$$anonymous$$ight be a bug, it shouldn't be hidden by default.

avatar image doublemax · Oct 07, 2016 at 12:00 AM 0
Share

Do you have any other scripts that might hide the cursor? $$anonymous$$g. several camera controller scripts do that.

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by hilfygame-studio · Feb 20, 2020 at 02:08 PM

had same issue, just restarting unity worked for me (remember to safe),had same problem at me it was just restarting unity, no scripting issues

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 hilfygame-studio · Feb 19, 2020 at 09:56 PM 0
Share

so short it would be:

  public bool cursorOn;
  
  void Update()
  {
     if(cursorOn)
     {
         ShowCursor();
     }
     else
     {
         HideCursor();
     }
  }
  
 public void ShowCursor
  {
      Cursor.visible = true;
      Cursor.lockState = CursorLock$$anonymous$$ode.None;
  }
  
 public void HideCursor()
  {
      Cursor.visible = false;
      Cursor.lockState = CursorLock$$anonymous$$ode.Locked;
  }


just check the cursorOn Bool in the inspector and it worked fine for me

avatar image
0

Answer by adamstepinski · Oct 21, 2020 at 07:24 AM

in my case an external script on Camera executing every frame hid the cursor

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 bruceweir1 · Dec 03, 2021 at 07:10 PM

Here is the solution. Just apply this script to an active gameobject in your scene.

Note that in the Editor, the game frame needs to have focus straight after you press Play for this to work correctly (ie click on it straight after clicking the Play button)

 public class LockCursor : MonoBehaviour
 {
 
     void Start()
     {
         Cursor.lockState = CursorLockMode.Locked;
         Cursor.visible = false;
     }
 
     void OnApplicationFocus(bool hasFocus)
     {
         if (hasFocus)
         {
             Cursor.lockState = CursorLockMode.Locked;
             Cursor.visible = false;
         }
     }
 
 }
 
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

80 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

Related Questions

Why do custom hardware cursors only work in exclusive mode? 0 Answers

"Cursor.lockState = CursorLockMode.Locked" causes Unity to run in slow motion 0 Answers

Way to lock cursor to center and still interact with Worldspace ui 0 Answers

My cursor is not displaying in Unity, what should I do?,My cursor is not displaying in Unity edit mode, what should I do? 0 Answers

Problem with Prefab - Following cursor 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