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 Madswint · Jan 17, 2014 at 09:08 AM · inputcursorfalsetrue

Disabling Mouse Look with Escape wont work?

 var CursorLocked = true;
 
 function Update()
 {
 if (Input.GetKey(KeyCode.Escape))
     CursorLocked = false;
     
 else
     CursorLocked = true;
    
     Screen.lockCursor = CursorLocked;
     
     if(CursorLocked == false) {
     GetComponent("MouseLook").enabled = false;
     //disable begge mouse look scripts af spilleren
     }
       if(CursorLocked == true) {
     GetComponent("MouseLook").enabled = true;
     //disable begge mouse look scripts af spilleren
     }
     
 }

This is what I have got. It works, kind of.. I'm trying to make it so if mouselook is false so is mouselook. Thing is, it only sets CursorLocked to false if you hold down Escape?

Side note: I have 2 mouselooks, one on camera one on player prefab, how would I get to the child camera of the player to disable it's mouselook? I cant get this to work since I dont know what is going on and what to search on google. Any help 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

Answer by Phles · Jan 17, 2014 at 02:46 PM

Hey there. The way that code is structured CursorLocked will only be true while you are holding down escape, you can change this by using Input.GetKeyDown(), but there are other problems with that code as well, in your else you set CursorLocked to true then use the the value in an if which will always be true as you just set it. Try the code below it should make escape toggle the CursorLocked value on each down press and enable/disable your mouselook component.

 var CursorLocked = true;
 
 function Update()
 {
 
 if (Input.GetKeyDown(KeyCode.Escape))
 {
     CursorLocked = !CursorLocked
 }

 if (CursorLocked == true)
 {    
         Screen.lockCursor = true;
         GetComponent("MouseLook").enabled = false;
 }
 else {
     Screen.lockCursor = false;
     GetComponent("MouseLook").enabled = true;
 }

 
 }


Hope this helps.

Phill

Comment
Add comment · Show 6 · 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 Madswint · Jan 17, 2014 at 04:02 PM 0
Share

Hmm, what this does, is when I start the game, you have to press ESCAPE to hide the mouse. That's one problem, the other is that to hide the mouse, you have to press escape again, but what I'm looking for is if you just click inside the game it hides it.

The old one worked that way, but it wouldn't activate it the way you made it do. Any ideas?

avatar image Phles · Jan 17, 2014 at 04:53 PM 0
Share

Ok I think I understand what you want to happen now, I edited the code in my answer accordingly.

avatar image Phles · Jan 17, 2014 at 04:58 PM 0
Share

Though if you only want to hide the cursor you may want to use Screen.showCursor = false; ins$$anonymous$$d of the lock.

avatar image Madswint · Jan 17, 2014 at 05:44 PM 0
Share

The lock makes it stay in the middle which is pretty important

avatar image Madswint · Jan 17, 2014 at 05:47 PM 0
Share

Now it starts locked, but it also starts with mouselook disabled :P. It's al ot harder thna I figured it would be to just have something like this :O

Show more comments

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

19 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

Related Questions

CursorAnim.cs (28,17): error CS0029: Can not implicitly convert type 'bool' to `UnityEngine.Texture2D ' 1 Answer

Add Cursor (Top-Down-Shooter) 1 Answer

SetActive - setactive(true) for one object, setactive(false) to the rest 1 Answer

Disable mouse input and cursor in game 2 Answers

How do you select an object with the cursor and retrieve data from that object selected? 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