如何在滑块上统一设置背景图像?

时间:2014-05-30 05:05:34

标签: unity3d slider unityscript

如何在滑块上设置背景图像??
或者我可以将附加材料更改为滑块,并且可以在单击时更改它。??

如果slider variable ==1的值可以设置图像1,则  如果slider variable==2的值可以在滑块上设置图像2.可能,.. ??

void OnGUI(){
        GUI.skin=myskin;
        GUILayout.BeginVertical ();
        GUILayout.Box ("sliderValue : " +  Mathf.RoundToInt(sliderValue));

        sliderValue = GUILayout.HorizontalSlider(sliderValue ,1.0f, maxSliderValue);
        if (sliderValue == 1) {


                }

    }

1 个答案:

答案 0 :(得分:0)

是的,你可以。只需更改背景和拇指样式。

float sliderValue;
float maxSliderValue = 2.0f;
public GUIStyle backgroundStyle;
public GUIStyle thumbStyle;
public Texture2D tex, tex2, thumbTex;

void OnGUI()
{
    GUILayout.BeginVertical ();
    GUILayout.Box ("sliderValue : " +  Mathf.RoundToInt(sliderValue));

    thumbStyle.normal.background = thumbTex;
    thumbStyle.fixedWidth = 20;
    thumbStyle.fixedHeight = 20;

    if (Mathf.RoundToInt(sliderValue) == 1)
        backgroundStyle.normal.background = tex;
    else
        backgroundStyle.normal.background = tex2;

    sliderValue = GUILayout.HorizontalSlider(sliderValue ,1.0f, maxSliderValue, backgroundStyle, thumbStyle);
}