- Home /
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;
}
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
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)
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!
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
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;
}
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.
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
Follow this Question
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