- Home /
(Unity 5.2.3f1) How to block system cursor to not to generate events on mouse click but allow it to custom cursor script?
Hi all. I created my own custom cursor which uses standard event system and pointer event data (part of code below):
PointerEventData pointer = new PointerEventData(EventSystem.current);
if (buttonRect.Contains(new Vector2(cursor.transform.position.x, cursor.transform.position.y))) {
if(Input.GetKeyDown(KeyCode.Mouse0)) {
ExecuteEvents.Execute(buttonButton.gameObject, pointer, ExecuteEvents.pointerDownHandler);
(...)
I also locked cursor and made it invisible.
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
Everything works fine until some UI object is not placed in center of the screen right under the locked system cursor. Then when I click mouse left button instead of processing my custom mouse script it process the locked cursor click event. Is there possible way to block those system cursor events and allow only my custom cursor events from script to be used?
Answer by adan_eslavo · Dec 31, 2015 at 01:38 PM
(Unity 5.3.0f4) Finally, I found solution to my own problem. I solved it by disabling button component in button, when code detects that there's system cursor over it. When my own custom cursor shows up and moves over button (so there are two cursors over one button) then I just reenable the component. That was the only working solution which I found.