Search code examples
unity-game-enginelistenermarkervuforia

Unir y - how i Put marker in object 3D (.obj) and get the touch listener of it


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


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 OnMouseDownfunction in it. This will detect the click/tap on the colliders.
    More about OnMouseDownhere: https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnMouseDown.html
    Way2: You can Raycaston 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
                }
            }
        }
    }