Change the mouse picture into the one you want in unity 3D
Today I looked at how to change the picture of the mouse in unity. This is because I have seen some games with their own mouse style before, like some with a sword and some with a hand. Needless to say, first download a mouse-style picture, as long as the picture is supported by U3D can be like png. The idea is to use our own picture instead of a mouse-style picture.
The code is as follows (on Cube)
Using System.Collections
Using System.Collections.Generic
Using UnityEngine
Public class NewBehaviourScript: MonoBehaviour {
Public Texture2D mousetexture;// custom mouse styl
Public Texture2D mouse_time;// Custom Styl
/ / Use this for initialization
Void Start () {
GetComponent () .material.color = Color.grey;// modifies the color of Cube
Mousetexture = Resources.Load ("cur"); / / load the picture of the sword
Mouse_time = Resources.Load ("tu"); / / load the picture of the sword
Cursor.SetCursor (mousetexture, Vector2.zero, CursorMode.Auto); / / the icon initialized to the sword
}
/ / Update is called once per frame
Void Update () {
}
Private void OnMouseOver ()
{
Cursor.SetCursor (mouse_time, Vector2.zero, CursorMode.Auto); / / switch mouse style when entering
}
Private void OnMouseExit ()
{
Cursor.SetCursor (mousetexture, Vector2.zero, CursorMode.Auto); / / restore on departure
}
}