Ji, im new in unity, im doing an app that is a body of a person, then you can tap/hit on you’re mobile for Example the head and the app changes the to another scene.
So what i wanna do is put like kind of buttons in some parts of the body and when the users click it, changes the scene, the proble is that if i put static buttons, if you zoom in/out or rotate the object, the buttons are not gonna move, so how can i attach/put this buttons or listeners to the object?
Pd. I searched and i saw that you can put like some parts with other color and detect the color but idk if this is the best solution
Way1:
You can put a Collider
in each individual part of the body, like head leg etc.
Then, add script to each of the parts with OnMouseDown
function in it. This will detect the click/tap on the colliders.
More about OnMouseDown
here: https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnMouseDown.html
Way2: You can Raycast
on mouse click or tap and check which object it is hitting.
void Update ()
{
if (Input.GetMouseButtonDown(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
//Select Stage
if (hit.transform.name == "Head")
{
//Clicked Head
}
}
}
}