This is a rather simple problem, but I can’t fix it, I’ve looked for several answers for this but I can’t get it to work.
I have a gameobject which is a raw image, what I want is that when I click on this image another image appears, I can already get it to work on keyboard, but I need with mouse as well, the somewhat interesting bit is that script tied to this gameobject just holds a boolean data that is sent to other scripts, those make the image appear, something like this
public bool touched = false;
void onMouseDown(){
touched=true;
}
That is everything I need it to do, so that when I clicked the object, the variable changes, then the rest take care of it, but I just can’t get it to work.
I’ve looked for onMouseDown methods and all sorts of stuff, and it either doesn’t work at all or works regardless of where I click, be it the button or not.
public bool touched = false;
void Update()
{
OnMouseOver();
}
void OnMouseOver()
{
if (Input.GetMouseButtonDown(0))
{
touched = true;
}
}
That is my code now, it works, but it doesn’t matter where I click, rather than just the gameobject, from the other solutions I’ve found I can’t get anything to work.
I’m working on Unity 3D, and added a box collider to my gameobject, still, no luck.
What am I missing?