Hello! I’ve checked around for how to use a custom mouse cursor, I’ve gotten in to work with the Texture2D which it implies that it needs using this code:
Is there any way that I could cast this into a sprite instead? This way I wouldn’t have to work around adding another texture thingy for working with the same image that already is a sprite in my asset folder. Any tips on implementing this would be highgly appreciated
For anyone interested, I figured it out myself by looking through some other threads that were answered in a similar way. This is how I ended up converting my sprite to a texture.
Firstly, you have to go to your Sprite in your asset folder. Change the “Texture Type” to “Advanced”. Make sure “Read/Write Enabled” is checked. Now we are able to manipulate this thing. Here is the code that makes this sprite function as a texture as well:
Hi, in response to your answer…
i don’t think its necessary to write the pixel data into a new Texture2D object, you can simply access the texture via sprite.texture.
i’ve tested this using this function… no need to go into advanced options for your sprite.
hope it helps ^^
void SetCursor( Sprite sprite , Vector2 center ) {
Cursor.SetCursor (sprite.texture, center, CursorMode.Auto);
}
change CurserMode to ForceSoftware if you’d like the cursor to be the same size as your sprite.
Hey, this seems to be a bug that's been reported (and reportedly fixed in Unity 5.4), but your solution works fine during testing inside the editor, but when a build is created the texture for the cursor gets corrupted as soon as it's changed in your way. Changing sprites to texture type "Cursor" fixed this for cursor specific textures, however using the texture directly from the sprite in the way you describe seems to corrupt the image when it's being tested in a build.
Hey, this seems to be a bug that's been reported (and reportedly fixed in Unity 5.4), but your solution works fine during testing inside the editor, but when a build is created the texture for the cursor gets corrupted as soon as it's changed in your way. Changing sprites to texture type "Cursor" fixed this for cursor specific textures, however using the texture directly from the sprite in the way you describe seems to corrupt the image when it's being tested in a build.
– DannyBlackwell