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 EnderSeldon · Feb 17, 2014 at 04:46 PM · cursorlockcrosshair

Need to lock the mouse but not in middle - OCULUS RIFT

Hi, due to Oculus Rift, I need to lock the mouse but not in the middle, cause the middle, when you are using Oculus, is not the middle of the screen. Using Oculus you have 2 screens and I need to lock the cursor (or use another method) cause I'm using the Oculus tracker (with a drawed crosshair) to move the camera and trigger events. But the locked cursor is in the middle of the 2 Oculus screens and not matches with the crosshair (crosshair is well positioned). There's the code I'm using:

 // True if the menu is open and mouse is unlocked 
    var MenuOpen : boolean = false; 
    
    function Start () {
        UpdateCursorLock(); 
        Screen.showCursor = true;
    } 
    
    function Update() {
        // Check whether the menu button was released 
        if (Input.GetButtonUp("MenuOpen")) {
            MenuOpen = !MenuOpen;
            UpdateCursorLock();
        } 
    } 
    
    // Called each time the Gui needs to be drawn 
    function OnGUI () {
        if (!MenuOpen) {
            // Draw the crosshair 
            
            // Center the text inside the label 
            var centeredStyle = GUI.skin.GetStyle("Label");
            centeredStyle.alignment = TextAnchor.MiddleLeft;
            // Draw the label at the center of the screen 
            GUI.Label (Rect (Screen.width/4+60, Screen.height/2-25, 100, 50), "O", centeredStyle);
        } 
    } 
    
    function UpdateCursorLock() {
        Screen.lockCursor = !MenuOpen;
               
        Screen.showCursor = MenuOpen; 
    }
Comment
Add comment · Show 9
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 chillersanim · Feb 17, 2014 at 04:54 PM 0
Share

As far as know, you cannot set the position of the cursor. So you would need another way of doing it.
If you just want to know how much the cursor has moved, you could use the Input class (use the axes). The crosshair don't need to be drawn on top of the cursor, you can draw it where ever you want.

If you want to to have two cursors... Never seen that before, sorry.

Hope that helps.

Greetings
Chillersanim

avatar image perchik · Feb 17, 2014 at 05:01 PM 0
Share

I could imagine a very complex custom solution, where you hide the real cursor and replace it with two gui textures that you'd have to write some crazy code to move it well (in 3D)

avatar image EnderSeldon · Feb 17, 2014 at 05:57 PM 0
Share

No, I only need 1 cursor, but locked in the position = (Screen.width/4+60, Screen.height/2-25, 100, 50). Same position that my crosshair.

Regards!

avatar image chillersanim · Feb 17, 2014 at 08:26 PM 0
Share

If you want your cursor just locked, then it doesn't matter where it is. You could set the crosshair directly to the desired position, and if that is for some reason not possible (thirth party scripts for example), just create your own. Like I said, I don't think there's a way to set the cursor to a position.

If you want the cursormovement, you should use the input axis for the cursor.

Greetings
Chillersanim

avatar image EnderSeldon · Feb 17, 2014 at 09:18 PM 0
Share

If I can't lock the cursor where I need, I want to know if is possible to change the on$$anonymous$$ouseOver in this script for another function, or raycast or something to load the function when the crosshair will be over the collider.

 var levelToLoad : String;
 var plane : GameObject;
 var delay : float;
 
  
 function Start () {
 plane.renderer.material.color = Color.black;
 
 }
  
  
 function On$$anonymous$$ouseOver () {
 delay += Time.deltaTime;
 // here the 2 is the time that you want before load the bar
 if(delay >=2)
 {
 plane.renderer.material.color = Color.green;
 Application.LoadLevel(levelToLoad);
 // buttom active >> load your scene
 }
 else
 {
 plane.renderer.material.color.g = delay/2;
 // loading bar is increasing ( delay/2 * 100 = percentage of loading)
 }
 }
 function On$$anonymous$$ouseExit () {
 delay = 0;
 plane.renderer.material.color.g = 0.1;
 }
Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by EnderSeldon · Feb 18, 2014 at 02:00 AM

I'm trying but I do not know what it is supposed to do. I do not know how to attach my functions

function OnMouseOver () { delay += Time.deltaTime; // here the 2 is the time that you want before load the bar if(delay >=2) { plane.renderer.material.color = Color.green; Application.LoadLevel(levelToLoad); // buttom active >> load your scene } else { plane.renderer.material.color.g = delay/2; // loading bar is increasing ( delay/2 * 100 = percentage of loading) } } function OnMouseExit () { delay = 0; plane.renderer.material.color.g = 0.1; }

with your code but I appreciate your effort and your help.

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 chillersanim · Feb 18, 2014 at 08:05 AM 0
Share

You would need to use my code in the update function. On$$anonymous$$ouseOver is called through $$anonymous$$onoBehaviour, but needs the mouse. Because you don't have the mouse, you need to do it yourself.

Just check in each frame (or each x frames) if the crosshair is above your object.

Greetings
Chillersanim

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

20 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

Related Questions

how to lock a cursor 1 Answer

Lock the screen 1 Answer

Lock cursor everywhere not center,how? 1 Answer

Modifying the pause menu to have screen.lockcursor on at start 1 Answer

Lock Cursor not working right 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