Hello I have a quick but important question. Is there any way to make Sprites Clickable(like GUI) through a script without using GUI Texture? I simply want to make my sprite game objects(all they have on them is a sprite renderers) be able to take me to different scenes when I click on them. The reason why I don’t want to use GUI Texture is because the sprite gives a more better look than the GUI Texture(you’ll have to see it to know what I mean, but I won’t show anything). Hope you guys can help me.
Definitely it involves 3 steps
- Check if the user has clicked the mouse
- Check if the positions of the Mouse and sprite match or within a certain parameter
- Run your code
first two are done for you
you just need to add a collider to the sprite. (not sure if 2D ones work, doesn’t mention them in the docs)
then this code.
public class MyGUISprite : MonoBehaviour {
void OnMouseDown()
{
print("clicked")
//do something
}
you can attach this to your sprite object…