Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • 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
9
Question by pdunton · Apr 27, 2014 at 09:44 PM · cursor

Cursor.setCursor hotSpot to center of image

I have a couple of custom cursors in my game's shop. All of them need to have the hotSpot in the center of the image, but I've tinkered a lot with the hotSpot argument and I cant seem to get it away from the default top-left. Please help. Thanks.

Comment
Add comment · Show 1
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 teslatron · Apr 28, 2014 at 12:32 PM 0
Share

Have you tried "new Vector2(16,16) for your hotspot? Assu$$anonymous$$g you are using 32x32 texture for the cursor.

2 Replies

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

Answer by Cherno · Apr 28, 2014 at 01:17 PM

image.width / 2 and image.height / 2 should do the job. Also, be sure to have your cursor images imported as cursors in the import settings.

Comment
Add comment · Show 3 · 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 Jure-Veler · Jun 25, 2015 at 08:02 AM 0
Share

Just what i was looking for, thanks !

avatar image B4ttleCat · Jun 01, 2020 at 12:47 AM 0
Share

Perfect and couldn't be more succinct. Thank you so much.

avatar image Durium · Mar 06 at 08:38 PM 0
Share

THANKS <3!!

avatar image
11

Answer by cowhi · Oct 09, 2014 at 12:58 PM

Here is a full working example in C#:

 using UnityEngine;
 using System.Collections;
 
 public class MouseScript : MonoBehaviour {
 
     public Texture2D cursorTexture;
     private Vector2 cursorHotspot;
     
     // initialize mouse with a new texture with the
     // hotspot set to the middle of the texture
     // (don't forget to set the texture in the inspector
     // in the editor)
     void Start () {
         cursorHotspot = new Vector2 (cursorTexture.width / 2, cursorTexture.height / 2);
         Cursor.SetCursor(cursorTexture, cursorHotspot, CursorMode.Auto);
     }
 
     // To check where your mouse is really pointing
     // track the mouse position in you update function
     void Update () {
         Vector3 currentMouse = Input.mousePosition;
         Ray ray = Camera.main.ScreenPointToRay (currentMouse);
         RaycastHit2D hit = Physics2D.Raycast (ray.origin, ray.direction);
         Debug.DrawLine (ray.origin, hit.point);
     }
 }
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 Sanyika66 · Jun 14, 2016 at 08:48 AM 0
Share

Hey man, thanks, it worked. I had an issue because in my game I use only one cursor and I can't set it's hotspot in the inspector. Cherno said this, too, but you provided the script for me. Thanks!

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.

Follow this Question

Answers Answers and Comments

27 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

Related Questions

How to lock cursor in WebGL 1 Answer

How to constrain cursor to surface? 2 Answers

Mouse Cursor Problem 2 Answers

Cursor appears dark in game 0 Answers

Cursor.SetCursor() not working when building to UWP 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges