Search code examples
c#unity-game-enginefbx

Accessing different parts of an FBX model in unity 3d


I am new in Unity3d and having problem accessing different parts of a ted bear(like hands, feet) on touch. I've FBX model of ted bear and I gave tags to each part but when I click on specific part , it gives me tag of whole baseModel not of that specific part.

That's how my FBX model looks like

enter image description here

In inspector , these are its settings

enter image description here

Code which I'm using:

void Update () 
{
    if (Input.GetMouseButtonDown(0)) 
    {
        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        if (Physics.Raycast(ray, out hit,Mathf.Infinity))
        {
            Debug.Log( "BodyPart Tag: " + hit.collider.tag );

            switch (hit.collider.tag) 
            {
                case "head":
                {
                }
                case "leg":
                {
                }
            }
        }
    }
}

I want to perform specific action based on tag.


Solution

  • You should delete your Collider component from your main object and add Collider to each sub-part of your object. Otherwise when you click the object, the function will terminate after hitting the first collider which is the parent object's box collider in your case.