I’m trying to make one of make objects have 2 areas that can be clicked. The 2 areas are actually going to act like buttons and depending on which button is pressed a specific action is performed.
Any help will be appreciated
Cheers,
I’m trying to make one of make objects have 2 areas that can be clicked. The 2 areas are actually going to act like buttons and depending on which button is pressed a specific action is performed.
Any help will be appreciated
Cheers,
Maybe you can add two game objects as children to the main gameobject in question. If you want them invisible, disable the 2 new objects mesh renders but make sure they still have colliders. Then align each new object where you want your buttons to be.
Then use a ray that comes from the main camera position to the mouse pointer and monitor for
mouse clicks. This should get you headed in the right direction.
if ( Input.GetMouseButtonDown (0))
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
bool didRayHit = Physics.Raycast(ray, out hit);
if (didRayHit)
{
Debug.Log("You clicked " + hit.transform.name);
}
}
Let e know if you need more specific instruction than that.
@SpaceManDan That worked perfectly. Thanks for the help brother.