Saturday, November 12, 2022
HomeGame DevelopmentUnity button spotlight not working correctly after spawn

Unity button spotlight not working correctly after spawn


I type of solved it, however in a extremely hacky means.

Since I could not refresh the button hover occasions, I simply moved the mouse away from the button for a millisecond after which put it again on high of the button. Which does work, however its not very elegant answer.
Right here is the code if anybody has the identical drawback sooner or later.

utilizing System.Runtime.InteropServices;

int x_Pos, y_Pos;

[DllImport("user32.dll")]
static extern bool GetCursorPos(out int X, out int Y);

[DllImport("user32.dll")]
static extern bool SetCursorPos(int X, int Y);

public IEnumerator Mouse_Shuffle() {
    GetCursorPos(out x_Pos, out y_Pos);

    Cursor.seen = false;
    SetCursorPos(0, 0);

    yield return new WaitForSeconds(0.00000000000001f);

    SetCursorPos(x_Pos, y_Pos);
    Cursor.seen = true;
}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments