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 Alayna · May 01, 2012 at 07:11 PM · mousecursorlock

Cursor Locks/Hides but Will Not Reappear?

I am using two scripts to control the locking and unlocking of the cursor. Both are placed on the default unity First Person Controller and are in Javascript.

This script called "Mouse_Lock" hides and locks the cursor like intended.


      function Update () {
         Screen.lockCursor = true;
         }

This seperate script disables and enables the above script on a keypress.


function Update () {
if (Input.GetKeyUp("p")) {
    var mouseLock = GetComponent.< Mouse_Lock>();
    mouseLock.enabled = !mouseLock.enabled;
    Screen.showCursor = true;
    }
}

During runtime the cursor is hidden and locked to the center of the screen initially. When I press "p" the second script deactivates the first, which I confirmed by seeing it uncheck in the inspector. However the cursor never reappears for me to be able to click anything. It will allow me to click outside the game on the editor whereas the cursor reappears, and will allow me to click in game again untill it disappears from using the second script to toggle lockCursor on. I have tried other scripts with these functions together in one script but the cursor never reappears when toggling off lockCursor.

Im very new to scripting and I'm sure its something very obvious that I'm missing. Any help would be greatly appreciated. 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

1 Reply

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

Answer by T27M · May 01, 2012 at 07:25 PM

You don't really need to seperate this one. I only do that if the scripts are trying to accomplish different tasks.

Try this..

 function Start ()

 { 

     Screen.lockCursor = true; // Start the game with the cursor locked or not (true or false)

   

 }

 

 

 function Update () {

         

     if(Screen.lockCursor == false && Input.GetKeyUp("p"))

     {

         Screen.lockCursor = true;

     }

     else if (Input.GetKeyUp("p"))

     {

         Screen.lockCursor = false;

     }

 

 }
Comment
Add comment · Show 2 · 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 Alayna · May 01, 2012 at 07:40 PM 0
Share

Thanks! It works perfectly, and such a fast response!

avatar image DUDOMITER · Jun 15, 2014 at 08:31 PM 0
Share

T27$$anonymous$$ - YOU ARE GOOOOOOOOOOOOOOD TNX 2 YOU I FIX $$anonymous$$Y PROBLE$$anonymous$$ TO . I WASTE ALL DAY BUTH YOUR POST $$anonymous$$A$$anonymous$$E $$anonymous$$Y EAVNING BETER TNX ONE $$anonymous$$ORE TI$$anonymous$$E .

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

where should i put this script 2 Answers

Locking cursor without changing position 1 Answer

error CS8025: Parsing error 1 Answer

Cant unlock cursor with FPS prefab 2 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