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 09, 2012 at 02:21 PM · mouseglitchlockfocus

Screen.lockCursor Acting Irregular

Hello, I am using this script to control locking of the mouse in Unity WebPlayer, but there are some weird irregularities.

 // for Standalone initial screen locking
      function Start ()
         { 
             Screen.lockCursor = true; // Start the game with the cursor locked or not 
         }
         function Update () {
             if(Screen.lockCursor == false && Input.GetKeyUp("p"))
             {
                Screen.lockCursor = true;
             }
             else if (Input.GetKeyUp("p"))
             {
                Screen.lockCursor = false;
             }
         }
     // Control Screen locking when focusing on the webplayer
         function OnApplicationFocus (){
          if(Screen.lockCursor == false){
          Screen.lockCursor = true;
          }
          }

When I load the webplayer the mouse is free to move the camera and I must click outside the player and then back to the player to get the mouse lock to activate (using Firefox). However the worst glitch is that I have a bunch of objects in the scene that I am using as triggers (for things like picking up items, turning on lights, starting animations etc) , and when the mouse is not visible from locking the cursor I cannot click any of them. When I start the game if I don't click outside and back in to activate the focus part of the script I can click anything just fine (but the mouse is moving about the scene without being in the middle of course). Every time I toggle the script when locked and centered it I cannot click anywhere though looking around is normal, and as soon as I toggle it off I can click everything again. To make it even more confusing, using the exact same build in the standalone player and in the editor nothing is wrong at all. I would really appreciate help with this as I've spent an entire day trying different configurations to fix this.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by maroonrs2 · May 09, 2012 at 02:39 PM

 var i:boolean = true;
 function Start()
 {
     Screen.LockCursor = true; //Correct!
 }
 
 function Update()
 {
      if(i)
      {
           Screen.LockCursor = true;
      }
      else if(i != true)
      {
           Screen.LockCursor = false;
      }
      if(Input.GetKeyUp(KeyCode.P))
      {
           if(i)
           {
                i = false;
           }
           else if(i != true)
           {
                i = true;
           }
      }
 }

What I Think It's Doing Is Not Rendering That Screen Is Currently Locked. So Here Is A Simple Declaration, Tested And Everything. Now When You Declare Your Focus, It Only Checks For It Being Locked. In This Case It Hasn't Been Locked Already. So Now You Can Simply Put That Coding In At The End. Any Questions Feel Free To Ask!

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 fafase · May 09, 2012 at 03:08 PM

I am not so sure about your description. I would guess what you mean is when playing if you click out of the webplayer you don't control the game anymore. I am probably wrong though. If so, you need to use

 function Awake(){
 Application.runInBackground = true;
 }

if not, I did not get it then. Also you can simplify your code with

 function Start ()
         { 
             Screen.lockCursor = true; // Start the game with the cursor locked or not 
         }
         function Update () {
             if(Input.GetKeyUp("p"))
             {
                Screen.lockCursor = !Screen.lockCursor;
             }
         }
     // Control Screen locking when focusing on the webplayer
         function OnApplicationFocus (){
          if(!Screen.lockCursor){
             Screen.lockCursor = true;
          }
          }
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 Alayna · May 09, 2012 at 04:00 PM 0
Share

Thank you for simplifying my script!

Sorry for not clarifying, what I meant was that even when I manage to have focus in the webplayer, while Screen.lockCursor is active (and the mouse is hidden and presumably in the middle of the screen) I cannot click any ingame objects(But I can move around and look normally. However when I toggle the locking off ingame (for menus) I can click the objects I should be able to click while the mouse is locked to the center. It seems that I can only click objects (say to turn on a lightswitch with a collider) when the cursor is visible.

avatar image fafase · May 09, 2012 at 06:28 PM 0
Share

I am not familiar with that feature but regarding the documentation http://unity3d.com/support/documentation/ScriptReference/Screen-lockCursor you seem to describe the normal behaviour. I guess if you want to interact with object when it is locked (hidden) you need as you said to add a trigger collider and trigger a gui that would either unlock the mouse pointer or else use the keyboard.

avatar image Alayna · May 09, 2012 at 07:45 PM 1
Share

I figured it out! I had a targetting reticle(That had a collider for some reason) that was directly infront of the mouse so when it was in the center it always clicked that ins$$anonymous$$d of the object it was supposed to.. Thank you for all your help!

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

6 People are following this question.

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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Cursor Locks/Hides but Will Not Reappear? 1 Answer

Hiccup between player movement and mouse control after game start. 0 Answers

Having a little issue with a script ... A script to hide the mouse, ("Parsing Error" and "Unexpected Symbol 'else' ") The script works now :) 3 Answers

Mouse Look and Character Motor off but i can still see :( help plox? 5 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