2017-02-14 121 views
0

我想使用腳本修改材質的「TintColor」,但在執行此操作時,以下錯誤即將發生 '材質沒有顏色屬性'_TintColor'' 。材質沒有顏色屬性'_TintColor'

我用Google搜索了一下,但是所有的努力都是徒勞的。 我看過這篇文章,它說它可以使用腳本進行修改。

https://forum.unity3d.com/threads/control-the-tint-color-of-the-material.23031/

着色器,我現在用的就是 '精靈/默認'

public Color[] colors = { new Color(42/255.0f, 246/255.0f, 229/255.0f,1),new Color(20/255.0f, 127/255.0f, 255/255.0f,1),new Color(73/255.0f, 3/255.0f, 198/255.0f,1); 
Debug.Log(renderer.material.GetColor("_TintColor")); 
//renderer.material.SetColor("_TintColor", colors[2]); /*This eventually I want to use */ 

我試着用alpha值玩,但沒有奏效

我不知道我做錯了什麼。這將是非常有益的,如果有人可以指出我的錯誤或讓我知道/分享鏈接,更改材質的顏色'TintColor'

回答

1

Shader'Sprites/Default'沒有「_TintColor」屬性,而是一個「_Color」屬性。因此,所有你需要做的就是改變

Debug.Log(renderer.material.GetColor("_TintColor")); 

Debug.Log(renderer.material.GetColor("_Color")); 
+0

我接受你的答案,但與此相關的一個問題。如何知道'_TintColor'或'_Color'或任何其他屬性是否暴露 –

+1

@AshishSingh您可以通過[下載「內置着色器」](https:// unity3d)查看默認Unity着色器的底層着色器代碼。 com/get-unity/download/archive)爲你的相應的Unity版本。這應該爲您提供所有關於它們各種屬性的信息。 – Serlite

+0

@AshishSingh。您可以單擊材質的上下文菜單(右上角的齒輪),然後單擊「選擇着色器」。你會看到所有的着色器屬性 – luizcarlosfx