- Home /
Lock mouse position with a Rect, possible?
I've been breaking my head looking for a way to lock the possible position of the mouse inside a Rect (basically, inside the webplayer's window, but I assume the solution would be the same).
The reason I think it should be possible is because it's also possible to lock the co-ordinates of the mouse to Screen.width/2,Screen.height/2.
Before you tell me to 'just lock the position and use a custom cursor texture that's locked inside the specified Rect', I've tried exactly that, and it does work. And sure, instead of using the mouseposition for things in game you cast a ray from the texture's position, etc. But you can no longer interact with the GUI buttons, which is a dealbreaker.
So if anyone would have any suggestions I'd be very, very, very thankful! I hope I was clear enough in explaining it.
Well, guess I'll make this a bounty then, since I'm really curious to see if this is somehow possible. :)
Answer by Mike 3 · May 05, 2011 at 06:42 PM
It's not possible with the current API alone, LockCursor has very limited use there
It is however possible with a native plugin, but for that you're going to need unity pro and some c++/c/objc knowledge, depending on platform, as well as platform specific API knowledge
Thanks for answering. Shame, I cannot afford Pro at this moment - being a poor student.. Guess I'll wait a little longer, and if no one else has a viable suggestion I'll accept your answer. ;)
Hah, well I guess this is the easiest bounty you've ever won, congratulations :). Now I just need to magically figure out a way to get pro without going broke.. / mumbles something about being a poor student/ :p
Even pro wouldn't help because native code plugins are not allowed in the webplayer. I don't see any way to implement that behaviour in the webplayer. Even if Unity extend the lockCursor functionality it will still be possible to break that limitation by pressing ESC. The only way i can see is that you do it with a custom cursor and handle the gui-events yourself. It's a nasty piece of work, but if you need the restrictions so badly that's at least a way ;)
Oh, true, I hadn't seen the webplayer bit. A plugin would be useful with standalones at any rate.