Unity3d 在预置中实例化后无法更改点光源的颜色

Unity3d 在预置中实例化后无法更改点光源的颜色,unity3d,Unity3d,我有一个预制点光源,可以在球体周围产生光晕。根据“类型”(健康、个性、天赋),发光的颜色必须改变。这是我的密码 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(

我有一个预制点光源,可以在球体周围产生光晕。根据“类型”(健康、个性、天赋),发光的颜色必须改变。这是我的密码

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;
}
GameObject glow=(GameObject)实例化(glowPrefab,新向量3(0,0,0),四元数.identity);
glow.transform.parent=child.transform;
glow.transform.localPosition=新矢量3(0,0,0);
开关(类型)
{
案例“健康”:
child.renderer.material=健康;
glow.GetComponent().color=新颜色(254f、137f、96f、255f);
//Log(“健康颜色”+glow.light.Color);
打破
“人格”一案:
child.renderer.material=个性;
glow.GetComponent().color=新颜色(137f、254f、96f、255f);
//Log(“Personality Color”+glow.GetComponent().Color);
打破
案例“人才”:
child.renderer.material=天赋;
glow.GetComponent().color=新颜色(137f、96f、254f、255f);
//Log(“人才颜色”+glow.GetComponent().Color);
打破
}
虽然debug.log显示灯已经改变,但在游戏中,它仍然是白色的。 有趣的是,当它运行时,场景显示五彩灯光-

但是,在游戏中,颜色是白色的-

单击单个灯光时,颜色为白色-

即使我改变了预设的颜色,灯光的颜色仍然是白色的

如何检查颜色在何处更改?是否有可用于记录的事件


谢谢

这可能是因为您传入了错误的颜色数据。采用0-1之间的RGBA值。您可以将值转换为正确的RGBA值,也可以将其用于特定的0-255 RGBA值

glow.GetComponent<Light>().color = new Color32(254,137,96,255);
// OR
glow.GetComponent<Light>().color = new Color(1, 0.92, 0.016, 1); // Yellow
// OR
glow.GetComponent<Light>().color = new Color.yellow;
glow.GetComponent().color=newcolor32(254137,96255);
//或
glow.GetComponent().color=新颜色(1,0.92,0.016,1);//黄色的
//或
glow.GetComponent().color=new color.yellow;