Hyarch
1
Can some one help me figure out why this code doesn’t work
I need to Change the smoothness and other properties of the shader on alot of objects after there created
loadedObj.GetComponentInChildren<Renderer>().material.shader = Shader.Find("Standard");
loadedObj.GetComponentInChildren<Renderer>().material.SetFloat("_Glossiness", 0);
Hm… I’m thinking… thinking… thinking. I GOT IT!!! I think it doesn’t work because there’s an error.
Here is how to deal with crazy hairy nasty dirty lines of code like the above:
How to break down hairy lines of code:
http://plbm.com/?p=248
One thing per line, check each thing along the way, find out which part is NOT what you expect it to be.
Generally, since only a few people here are mind-readers, here is how to report your problem productively in the Unity3D forums:
http://plbm.com/?p=220
2 Likes
somebody should really pin this stuff, and highlight it… twice.
Mauri
4
SetFloat("_Glossiness", 0)
likely should be SetFloat("_Glossiness", 0.0f)
.
Changing 0 to 0.0f instead won’t make a difference. The compiler will convert the integer to a float automatically as that is what the method wants.
Hyarch
6
I ended up getting this to work Thanks guys
IEnumerator Run() {
//file path
//string filePath = @"F:\VATICMOD\Data\azeroth_37_31.obj";
//string filePath = @"D:\Models\world\maps\silvermooncity\silvermooncity_44_12.obj";
string filePath = "Assets/Resources/world/maps/silvermooncity/be_signpost_eversong.obj";
if (!File.Exists(filePath))
{
Debug.LogError("Please set FilePath in ObjFromFile.cs to a valid path.");
}
//create stream and load
GameObject loadedObj = new OBJLoader().Load(filePath);
Debug.Log(loadedObj.name);
foreach (Transform g in loadedObj.transform)
{
GameObject f = g.gameObject;
f.GetComponent<Renderer>().material.shader = Shader.Find("Standard");
f.GetComponent<Renderer>().material.SetFloat("_Glossiness", 0);
Debug.Log(g.name);
}
// string newPath = "F:/VATICMOD/Assets/Resources/world/maps/silvermooncity/silvermooncity_44_12.fbx";
//FBXExporter.ExportGameObjToFBX(loadedObj, newPath, true, true);
// ObjExporter objExporter = new ObjExporter();
//ObjExporter.MeshToFile(loadedObj.GetComponent<MeshFilter>(),"test.obj");
yield return new WaitForSeconds(0);
}
1 Like