1
我有一顆鑽石精靈,我希望能夠從白色改變鑽石的顏色,它的原始顏色爲綠色。但是,我無法弄清楚如何做到這一點。如何在Unity中測試應用於物體的材質
public class MoveControl : MonoBehaviour {
// Update is called once per frame
void Update() {
if (Input.GetKey(KeyCode.A))
{
if (GetComponent<Renderer>().material.color == Color.white)
{
GetComponent<Renderer>().material.color = Color.green;
}
}
}
}
上面的代碼就是我現在使用的,它只適用於應用於精靈的材質,即白色,是一個精靈/默認着色器。這聽起來可能不是一個大問題,但是每當我應用不同顏色的不同材質(例如藍色),並更改其設置以使其具有精靈/默認着色器時,精靈將變得不可見。
我是新的團結,如果有人可以幫助我,那將是非常讚賞
在控制檯中,它表示「此行爲的引用腳本已丟失!」。它沒有按預期工作。 –
@NathanielOriecuia試試這個http://answers.unity3d.com/questions/347443/the-referenced-script-on-this-behaviour-is-missing-2.html – LongarMD