Mouse Cursor Not Centred

Hi all,

I’m trying to use a custom mouse cursor and am finding it difficult to have the click point directly in the middle of my chosen image. Ive tried a number of things but cant seem to get it working, any ideas?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MouseIcon : MonoBehaviour {
public Texture2D cursorEnter;
public Texture2D cursorExit;

	void OnMouseEnter () {
		Cursor.SetCursor(cursorEnter, new Vector2(10,10), CursorMode.Auto);
	}
	
	void OnMouseExit () {
		Cursor.SetCursor(cursorExit, new Vector2(10,10), CursorMode.Auto);
	}
}

Cheers,

Make sure you have imported your textures as texture type “cursor”. If you want to have the hot spot at the center of the image you can simply do this:

Vector2 hotSpot = new Vector2(cursorEnter.width / 2f, cursorEnter.height / 2f);
Cursor.SetCursor(cursorEnter, hotSpot, CursorMode.Auto);

The hot spot should be in pixels of the used image and is measured from the top left corner.