x


Lock cursor on the center of screen

i have tried many options with Screen.lockCursor = true; etc

so i was told its possible to use a dll file to lock the cursor in the middle of the screen system.windows.forms.dll is the one im told to use but i dont know how i would start to get it to work or what code i would use in c# to make the cursor center ,

the problem is that i put Screen.lockCursor = true; in code but when i do it OnMouseOver doesnt work or similar things like OnMouseEnter. it works perfectly fine without the lockcursor but with it the on mouse stuff doesnt work

i have tried running the game to see if its just a problem with the in house play .

things i have tried : Screen.lockCursor = true; Screen.lockCursor = false; (in the update)

if(Screen.lockCursor == false) Screen.lockCursor = true; (update also)

either need to fix the problem with lock cursor or use the dll method but i need to be told how to set it up, thanks for any help in advance!

more ▼

asked Jun 04 '12 at 09:41 PM

quantumarchi gravatar image

quantumarchi
41 7 12 14

whoops sorry i posted the wrong one.

Jun 04 '12 at 09:55 PM artsdcs

what do you mean?

Jun 04 '12 at 09:56 PM quantumarchi

artsdcs : i use this

function Start (){
    Screen.lockCursor = true; 
}
Jun 04 '12 at 09:57 PM Berenger

that makes no difference, even if it did what if the player uses escape the lockcusor changes to false automatically then.

Jun 04 '12 at 10:01 PM quantumarchi

In that case, set lockCursor to false when you don't want it locked, and true every frame otherwise. You can also use raycasting instead of OnMouseOver.

Jun 04 '12 at 10:32 PM Eric5h5
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

Hi. you could use triggers and instantiate gui text saying shop or something. something that means you dont have to use mouse over just enter an area and press for example e to get the action to happen :D

more ▼

answered Feb 03 at 03:53 AM

Romolopo gravatar image

Romolopo
3

(comments are locked)
10|3000 characters needed characters left

what I use so u can unlock it in mid game so u can be able to exit out (sorry its in java, u can allways make a new script)

// lock at beggining
function Start ()
{
Screen.lockCursor = true;
}
//unlock in mid game

function Update()
{
Screen.showCursor = false;

    if (Input.GetKeyDown(KeyCode.P))
        if (Screen.lockCursor)
        Screen.lockCursor = false;

    else{
    Screen.lockCursor = true;
}

}

more ▼

answered Jun 04 '12 at 10:28 PM

thenachotech1113 gravatar image

thenachotech1113
131 2 12 23

no exiting out isnt the problem! you can just press escape for that!

im sorry but people dont seem to be understanding,

Screen.lockCursor works! but it stops OnMouseOver from working on objects! In my game you need to put your mouse over barricades and shops etc for you to use them , GUI comes up, and you can do what you want from there,

But if Screen.lockCursor = true; then the OnMouseOver does not work. meaning the player cant upgrade and buy things, If Screen.lockCursor = false and the player puts their mouse over and object it works fine, so something about Screen.lockCursor is making it stop working

i must also add i need the cursor to be put in the middle of the screen because thats how i want the gameplay to be like, so if Screen.lockCursor does not work what else can i do?

i have been told a .dll file will allow me to do this But if there is a way to make Screen.lockCursor to work then please tell me .

thank you

Jun 04 '12 at 10:39 PM quantumarchi
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x496
x486
x234
x21

asked: Jun 04 '12 at 09:41 PM

Seen: 2226 times

Last Updated: Feb 03 at 03:53 AM