Hi everybody !
I have a problem with using materials. I create a gameObject and want to make him bit transparent. When I change the material in the editor all is fine but when I try to do it from script it doesn’t change.
Here is my source :
ObjectOnDrag = (GameObject)Instantiate(Prefab.gameObject, gameObject.transform.position, gameObject.transform.rotation);
ObjectOnDrag.name = Prefab.name + (number++).ToString();
ObjectOnDrag.layer = CONF.NORMAL_LAYER;
ObjectOnDrag.AddComponent(typeof(MeshCollider));
// Make it Transparent
foreach(Material mat in ObjectOnDrag.renderer.materials)
{
mat.color = new Color(mat.color.r,mat.color.g,mat.color.b,50);
}
Does someone know if there is somthing wrong with materials and unity by scripting. Thanks !