Hey, I used a script to change the color of a block. If i use it in the Awake function, it works perfectly. But if i use it in another function (UpdateColor) it doesn’t. Or did i just mess up something simple?
Code:
public class RandomColor : MonoBehaviour {
[HideInInspector]
public Color c;
Renderer rend;
void Awake () {
rend = GetComponent<Renderer>();
rend.material.shader = Shader.Find("Standard (Specular setup)");
// if (s.Equals(rend.material.shader)) Debug.Log("HAY");
c = new Color(Random.Range(0, 0.15f), 0.9f, Random.Range(0, 0.15f));
rend.material.SetColor("_SpecColor", c);
}
public void UpdateColor()
{
rend.material.SetColor("_SpecColor", c);
}
}
Calling of the UpdateColor method:
GameObject o = Instantiate(block, new Vector3(x, heights[x, y] - k, y), Quaternion.identity);
o.GetComponent<RandomColor>().c = World.c_stone;
o.GetComponent<RandomColor>().UpdateColor();