- Home /
Question by
Demonolith · Jun 15, 2018 at 12:53 AM ·
c#unity 5buttonscursor
Cursor changed on button hover, but how to change it back if object is destroyed?
So I have a UI with a cancel button. The cursor changes to a hand over the buttons, but if the cursor hovers over the cancel button and then I click it, the object is destroyed, therefore the script that changes it back into the default cursor no longer exists. Does anyone know of a way around this? At the moment here is my script...
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class PointerOnBtnHover : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
[SerializeField]
Texture2D cursor;
public void OnPointerEnter(PointerEventData eventData)
{
Cursor.SetCursor(cursor, Vector2.zero, CursorMode.Auto);
}
public void OnPointerExit(PointerEventData eventData)
{
Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
}
}
Comment
Best Answer
Answer by Feelnside · Jun 15, 2018 at 04:22 AM
Try to use the OnDestroy() event. For example:
void OnDestroy()
{
Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Dialouge isnt working 1 Answer
Unity Cursor changing back 1 Answer
How do GetButtonDown and GetButton work? 4 Answers