Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Custom cursor is not visible on second monitor in multi-display setup

Discussion in 'Scripting' started by ivanshv, Jul 23, 2019.

  1. ivanshv


    Apr 13, 2018

    short preamble. As I wasn't able to set the mouse cursor control with a joystick axis (which is essential for my project), I had to create a custom cursor with the code below. In a few words, my app is very simple, the user obtains the display coordinates on mouse click and writes them to csv file.
    And everything is working absolutely fine. But for one thing, the cursor is not visible on second display. I can obtain needed coordinates, but I don't see the pointer. I was trying to put a canvas with a panel rendered to Display2 (scree Space - Overlay), but it doesn't help. On the first display everything is perfect, but when I move the cursor to the second one it is not drown.

    This is the very final step of my project, would be glad to hear any advice. Thanks.

    Code (CSharp):
    2. public Texture2D cursorImage;
    4. private int cursorWidth = 70;
    5. private int cursorHeight = 70;
    6. public float horizontalSpeed = 2.0F;
    7. public float verticalSpeed = 2.0F;
    8. private Vector2 cursorPosition;
    10. private void Start()
    11. {
    12.     Cursor.visible = false;
    13.     cursorPosition = new Vector2(Screen.width/2f, Screen.height/2f);
    14. }
    16. private void OnGUI()
    17. {
    19.     float h = horizontalSpeed * Input.GetAxis("Horizontal") * Time.deltaTime;
    20.     float v = verticalSpeed * Input.GetAxis("Vertical") * Time.deltaTime;
    22.     cursorPosition.x += h;
    23.     cursorPosition.y += v;
    25.     GUI.DrawTexture(new Rect(cursorPosition.x, Screen.height - cursorPosition.y, cursorWidth, cursorHeight), cursorImage);
    26. }