本文實例為大家分享了unity通過slider調整物體顏色的具體代碼,供大家參考,具體內容如下
首先我們創建三個slider 和一個cube,為了方便查看,我把slider下面的handle分別改變顏色并和名字一一對應;
然后我們把腳本放在cube上,并且把三個slider分別 拖進去
具體腳本如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
using unityengine; using system.collections; using unityengine.ui; public class slidercolorhyp : monobehaviour { public slider redslider; public slider greenslider; public slider blueslider; private material hypmaterial; // use this for initialization void start () { //這里需要獲取cube的組件 hypmaterial = getcomponent<meshrenderer>().material; } // update is called once per frame void update () { hypmaterial.color = new color(redslider.value, greenslider.value, blueslider.value); } } |
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。
原文鏈接:https://blog.csdn.net/tianduyingcai0113/article/details/77915518