0
在Unity3D中,我试图设置我的刹车灯材料上的发光属性上的浮动 - 但没有任何运气。使用C#,我如何在我的发射属性上设置浮点数?
这里是我的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");
}
}
}
缺少什么我在这里?我也没有在控制台中发现错误,并且当我按下空格键时,我的调试日志在运行时显示。
感谢您的帮助!
不知道有什么统一但为什么启用关键字时,您使用大写字母,然后使用不同的情况下引用它?使用相同的案例会更加连贯吗? – Steve
史蒂夫,谢谢你的回复。非常感激。 因此,在启用关键字时,Unity3D将所有带下划线的大写字母作为第一个字符。作为参考,这里是关键字的链接(向下滚动一下): http://docs.unity3d.com/Manual/MaterialsAccessingViaScript.html 我使用了不同的情况下字符串在设置浮动功能模仿什么我在这里看到: http://docs.unity3d.com/ScriptReference/Material.SetFloat.html 我觉得我很亲密,但只是没有做正确的事情或缺少一个步骤。 –
@Steve这些是两个不同的**基于字符串的属性ID。你必须接受Unity团队的任何一致性问题。 –