在Unity3D中,我试图在我的刹车灯材料上设置发光属性的浮动-但没有任何运气。
下面是我的C#代码:
using UnityEngine;
using System.Collections;
public class BrakeLights : MonoBehaviour {
private Renderer Brakes;
// Use this for initialization
void Start () {
Brakes = GetComponent<Renderer>();
Brakes.material.shader = Shader.Find("Standard");
Brakes.material.EnableKeyword("_EMISSION");
}
// Update is called once per frame
void Update(){
//Brake lights
if(Input.GetKey(KeyCode.Space)){
Brakes.material.SetFloat("_Emission", 1.0f);
Debug.Log (Brakes.material.shader);
}else{
Brakes.material.SetFloat("_Emission", 0f);
Debug.Log ("Brakes OFF");
}
}
}这里我漏掉了什么?当我按空格键时,我在控制台中也没有得到任何错误,并且我的调试日志显示在运行时。
谢谢你的帮助!
发布于 2015-07-21 06:11:23
我发现成功地使用发射颜色,而不是为其强度设置浮点值。因此,例如,我会将发射颜色设置为黑色,以无强度/发射,并指定红色(在我的情况下)以使材质发光红色。
我还意识到我必须使用传统的着色器才能正常工作。
以下是工作的代码:
using UnityEngine;
using System.Collections;
public class Intensity : MonoBehaviour {
private Renderer rend;
// Use this for initialization
void Start () {
rend = GetComponent<Renderer> ();
rend.material.shader = Shader.Find ("Legacy Shaders/VertexLit");
rend.material.SetColor("_Emission", Color.black);
}
// Update is called once per frame
void Update () {
if (Input.GetKey (KeyCode.Space)) {
rend.material.SetColor ("_Emission", Color.red);
} else {
rend.material.SetColor ("_Emission", Color.black);
}
}
}https://stackoverflow.com/questions/31495500
复制相似问题