void OnGUI() { GUILayout.Label("Time to bake textures: " + elapsedTime); if (GUILayout.Button("Combine textures & build combined mesh")) { MB2_MeshBaker meshbaker = target.GetComponent <MB2_MeshBaker>(); MB2_TextureBaker textureBaker = target.GetComponent <MB2_TextureBaker>(); //These can be assets configured at runtime or you can create them // on the fly like this textureBaker.textureBakeResults = ScriptableObject.CreateInstance <MB2_TextureBakeResults>(); textureBaker.resultMaterial = new Material(Shader.Find("Diffuse")); float t1 = Time.realtimeSinceStartup; textureBaker.CreateAtlases(); elapsedTime = Time.realtimeSinceStartup - t1; meshbaker.ClearMesh(); //only necessary if your not sure whats in the combined mesh meshbaker.textureBakeResults = textureBaker.textureBakeResults; //Add the objects to the combined mesh meshbaker.AddDeleteGameObjects(textureBaker.GetObjectsToCombine().ToArray(), null, true, false); meshbaker.Apply(); } }