- Home /
Is creating a custom cursor in the player settings bad?
I have gone through a lot of custom cursor posts and none of them seem to use the simple drag and drop method of adding in a new cursor through the player settings and instead use a lot of GUI code. Is there some inherent downside to doing it the easy way?
Why you don't want to use OnBeginDrag() + OnDrag() + OnEndDrag() functions + simple code for changing cursor? Personally everything what I am doing is by scripts. Also if you create simple method for change cursor there is no much code for that
Answer by RafiXWPT · Aug 11, 2015 at 10:56 PM
There is no much code for that.
Firstly inherit from interfaces to your class: IBeginDragHandler, IEndDragHandler, IDragHandler
Then add:
public Texture2D cursorTexture;
public void OnBeginDrag (PointerEventData eventData)
{
SetNewCursor();
}
public void OnDrag (PointerEventData eventData)
{
//Do whatever you want.
}
public void OnEndDrag (PointerEventData eventData)
{
BackToNormalCursor();
}
void SetNewCursor()
{
Cursor.SetCursor(cursorTexture, Vector2.zero, CursorMode.Auto);
}
void BackToNormalCursor()
{
Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
}
As you can see there is no much code and you can easly add more fields with different cursor images for differend situations. Just remember to import cursor image as "Cursor".