Reputation: 67
When creating a mesh filter at runtime on android the model is becoming pink and in the unity editor works fine I attached the material like this
MeshRenderer renderer = gameObject.AddComponent<MeshRenderer>();
MeshFilter filter = gameObject.AddComponent<MeshFilter>();
Texture white = new Texture();
filter.GetComponent<MeshFilter>().transform.localScale = new
Vector3(0.0009f, 0.0009f, 0.0009f);
filter.GetComponent<MeshRenderer>().material.color = Color.white;
Upvotes: 1
Views: 1224
Reputation: 133
pink means "i've got no material on me"
heres probably where your problem is:
filter.GetComponent<MeshRenderer>().material.color = Color.white;
this sets the color of the material on the mesh renderer.
you need to give the mesh renderer a material first. Try this:
MeshRenderer renderer = gameObject.AddComponent<MeshRenderer>();
MeshFilter filter = gameObject.AddComponent<MeshFilter>();
Material = mathew; //---This is our material, mathew.
mathew = new Material(Shader.Find("Standard")); //--- first we construct mathew
mathew.color = color.white; //--- then we give mathew some color
filter.GetComponent<MeshFilter>().transform.localScale = new
Vector3(0.0009f, 0.0009f, 0.0009f);
filter.GetComponent<MeshRenderer>().material = mathew; //finally we attach mathew to his new friend, MeshRenderer.
There is an easier way to do it using public variables, but it seems your generating all your stuff on the fly. So i've gone with that.
Let me know if this works or not. Good luck!
Upvotes: 2