- Home /
Changing Mouse Cursor over 3d game object
Hi guys!
So I'm having a bit of trouble getting this little thing to work properly. What I want to do is have gameobjects in the world (doors, books etc) that change the mouse icon when i hover over them, to indicate they can be interacted with.
I've tried using both OnMouseOver and OnPointerEnter but neither seem to pick up the object i'm hovering over. I've tried casting a ray to pick it up too but it's not getting anything either. The game objects do have colliders on them (set as triggers).
I can get it working with the custom mouse icon if i put the Cursor.SetCursor in Start() but i can't seem to get it to work in any other way, and I don't want to permanently chagne the mouse icon, i just want to change it when i'm over specific objects.
Here's my code as it is at the minute (it's gone through a lot of changes with mouseover/pointerenter etc)
using UnityEngine; using System.Collections; using UnityEngine.EventSystems; using UnityEngine.Events;
public class MouseIcon : MonoBehaviour { public static bool queriesHitTriggers;
[SerializeField]
Texture2D cursor;
void Start()
{
queriesHitTriggers = true;
}
void OnPointerEnter ()
{
Cursor.SetCursor(cursor, Vector2.zero, CursorMode.Auto);
Debug.Log("Mouseover");
}
void OnPointerExit ()
{
Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
}
}
Any help would be appreciated greatly! Or if someone could point me to some resources even, I can't really find anything online that isn't deprecated or using GUI to draw things..
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How would I make a ListChangedEvent? 1 Answer
Problem with rotation Please Help Me 1 Answer
I have a problem with coins 1 Answer