I’m new to unity but I have some scripting basic aptitudes. my problem is: I have some sketchup model (.obj) that contains “groups”. I import them to unity using objImporter. the problem is that when the object is Imported, I do not have access to any subgroup, and i need that acces to change texture of part of my models. can someone help me with it please?
here is my code:
//object to spawn
var objToSpawn = new GameObject("my object name");
//Add Components
objToSpawn.AddComponent<Rigidbody>();
objToSpawn.AddComponent<MeshFilter>();
objToSpawn.AddComponent<BoxCollider>();
objToSpawn.AddComponent<MeshRenderer>();
objToSpawn.GetComponent<Transform>().localScale = new Vector3(0.001f, 0.001f, 0.001f); //the model use milimeters, so i scale it
objToSpawn.GetComponent<Transform>().position = pos;//i put it at the good position
objToSpawn.GetComponent<Collider>().attachedRigidbody.useGravity = false;
objToSpawn.GetComponent<Collider>().attachedRigidbody.isKinematic = true;//if i don't use it, when i put other component, it all explode
var holderMesh = new Mesh();
var newMesh = new ObjImporter();
holderMesh = newMesh.ImportFile("PATH/to/my/object.obj");
objToSpawn.GetComponent<MeshFilter>().mesh = holderMesh;//turn my object into a mesh
objToSpawn.GetComponent<MeshRenderer>().materials[0] = Resources.Load(texture) as Material;//whatever i put here i got default texture instance for the whole model
objToSpawn.GetComponent<Rigidbody>().interpolation = RigidbodyInterpolation.Extrapolate;
//try to get subgroups or whatever i can but i have no idea how
var allMesh = objToSpawn.GetComponentsInChildren<MeshFilter>();
foreach (MeshFilter child in allMesh)
{
Debug.Log(child.name);//write "my obect name" in the console
//instruction to assign a texture material to the group X
}
I don’t get the groups hierachy like if I just drag and drop my .obj into the scene, just the gameObject’s name i thanks you by advance, if i do it the wrong way I’m open to any advices.