Question by
Hellzscream47 · Sep 23, 2017 at 09:58 AM ·
mouse cursor
How to change mouse cursor with multiple textures based on tag
If i move my mouse to an object with tag , the mouse cursor should change to a texture and if mouse is not over any specified tagged object it should have a default cursor. By writing the below code, my mouse is stuck in the default cursor even if i move it to a tagged object.
public class Hover : MonoBehaviour {
public Texture2D defaultTexture;
public Texture2D attackTexture;
public Texture2D pickupTexture;
public Texture2D interactTexture;
public CursorMode curMode = CursorMode.Auto;
public Vector2 hotSpot = Vector2.zero;
// Use this for initialization
void Start () {
Cursor.SetCursor(defaultTexture, hotSpot, curMode);
}
// Update is called once per frame
void Update () {
}
public void OnMouseEnter()
{
if (gameObject.tag == "Enemy")
{
Cursor.SetCursor(attackTexture, hotSpot, curMode);
}
}
public void OnMouseExit()
{
Cursor.SetCursor(defaultTexture, hotSpot, curMode);
}
}
Any help would be appreciated ^_^
Comment
Your answer
