我预设一个point light,使一个球体发光。我改变了辉光的颜色。这里是我的代码 -
GameObject glow = (GameObject)Instantiate(glowPrefab,new Vector3(0,0,0),Quaternion.identity);
glow.transform.parent = child.transform;
glow.transform.localPosition = new Vector3(0,0,0);
switch(type)
{
case "health":
child.renderer.material = health;
glow.GetComponent<Light>().color = new Color(254f,137f,96f,255f);
//Debug.Log ("Health Color" + glow.light.color );
break;
case "personality":
child.renderer.material = personality;
glow.GetComponent<Light>().color = new Color(137f,254f,96f,255f);
//Debug.Log (";Personality Color" + glow.GetComponent<Light>().color );
break;
case "talent":
child.renderer.material = talent;
glow.GetComponent<Light>().color = new Color(137f,96f,254f,255f);
//Debug.Log ("Talent Color" + glow.GetComponent<Light>().color );
break;
}
虽然debug.log中显示,point light发生了变化,但在游戏中,它仍然是白色的。有趣的是,运行时,场景中显示五彩灯光:
在游戏中,颜色为白色:
当我点击一个单独的光,颜色为白色:
即使我改变 prefab 的色彩,灯光的颜色仍然是白色的。
如何检查那里的颜色被改变了?是否有一个事件,我可以用日志记录?
谢谢!
原文:unable to change color of point light after instantiating in prefab
来自@S.Richmond 的回答:
那将是因为你传递了错误的颜色数据。UnityEngine.Color需要0-1之间的RGBA值。你可以转换你的数据,为RGBA值或使用UnityEngine.Color32 工具明确 0-255 的RGBA值。