• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by FlashX · Sep 17, 2017 at 10:39 AM · cursor-customization

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,

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Bunny83 · Sep 17, 2017 at 10:56 AM

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image FlashX · Sep 17, 2017 at 12:34 PM 0
Share

ah your'e wonderful! That worked! Appreciate your help :)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

69 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Cursor disappears when other windows are open 0 Answers

Keeping the cursor in one spot... 2 Answers

Customized cursor : render after everything else 1 Answer

Have cursor appear with a different key press. 0 Answers

Possible to change size of cursor with Cursor.SetCursor? 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges