2016-12-01 39 views
1

私は小さなシミュレーションのための設定スクリプトを持っています。Unity GUIの色/スライダの色/ラベルの色を変更

カメラの背景色は黒です。私はラベルを持つGUI.Horizo​​ntalSliderを持っているとき、私はSlidercolorを変更する必要があります。さもなければそれをよく見ることはできません。

これらの色を設定する場所と設定方法を教えてもらえますか? "ContentColor"、 "BackgroundColorを" 働いていない。..

マイコード:あなたが欲しいものを

private int planetObjectsCount = 1;   // number of objects in the next scene 
private int skyObjectsCount = 1;   // number of objects in the next scene 
private int spaceObjectsCount = 1;   // number of objects in the next scene 

private void OnGUI() 
{ 
    GUI.color = SetGUIColor(); // Give GUI Elements a default Color 

    planetObjectsCount = Mathf.RoundToInt(GUI.HorizontalSlider(GetGuiRect(Screen.width/2, Screen.height * 2/8), planetObjectsCount, 1, 300));  // The Slider Element - store the value 
    skyObjectsCount = Mathf.RoundToInt(GUI.HorizontalSlider(GetGuiRect(Screen.width/2, Screen.height * 4/8), skyObjectsCount, 1, 100));    // The Slider Element - store the value 
    spaceObjectsCount = Mathf.RoundToInt(GUI.HorizontalSlider(GetGuiRect(Screen.width/2, Screen.height * 6/8), spaceObjectsCount, 1, 100));   // The Slider Element - store the value 

    GUI.Label(GetGuiRect(Screen.width/2, Screen.height * 3/8), "Objects on the Planet: " + planetObjectsCount.ToString());   // The Label for the Slider 
    GUI.Label(GetGuiRect(Screen.width/2, Screen.height * 5/8), "Objects in the Sky: " + skyObjectsCount.ToString());    // The Label for the Slider 
    GUI.Label(GetGuiRect(Screen.width/2, Screen.height * 7/8), "Objects in Space: " + spaceObjectsCount.ToString());    // The Label for the Slider 

    if (GUI.Button(GetGuiRect(Screen.width * 0.85f, Screen.height/2), "Build"))    // Menu Button 
    { 
     PlayerPrefs.SetInt("planetObjectsCount", planetObjectsCount);     // Store the values to the PlayerPrefs 
     PlayerPrefs.SetInt("skyObjectsCount", skyObjectsCount);        // Store the values to the PlayerPrefs 
     PlayerPrefs.SetInt("spaceObjectsCount", spaceObjectsCount);      // Store the values to the PlayerPrefs 
     LoadScene("Ingame");                // Load the simulation 
    } 

    if (GUI.Button(GetGuiRect(Screen.width * 0.15f, Screen.height/2), "Back"))  // Menu Button 
    { 
     LoadScene("MainMenu");                // Back to MainMenu 
    } 
} 

internal Rect GetGuiRect(float xPos, float yPos)    // Return a Rectangle for GUI Elements 
{ 
    float rectWidth = Screen.width/5; 
    float rectHeight = Screen.height/10; 

    xPos -= rectWidth/2; 
    yPos -= rectHeight/2; 

    return new Rect(xPos, yPos, rectWidth, rectHeight); 
} 

internal Color SetGUIColor()         // Set the GUI Color 
{ 
    return Color.cyan; 
} 

答えて

0

かなりわかりません。 しかし、私はGUIStyleまたはGUISkinを使用して問題を解決すると考えています。 GUIStyleを使用すると、使用するフォントとその色として多くの正当性を変更できます。したがって、それを作成し、それを使用するためのGUIコンポーネントを設定します。 GUILabelでは、例えば、あなたは三番目のパラメータとしてGUIStyleを渡すことができます。

public static void Label(Rect position, string text, GUIStyle style); 

そしてGUISkinあなたは全く新しいUIスタイルを作成することができるように、すべてのUIコンポーネントに分割これらGUIStylesのコレクションです。

しかしUnityはまた、コードを必要とせずにつまむことができ、OnGUIを使っている方がずっと良い方法であることをUI systemが提供することを知っておくべきだと思います。例として、UnityマニュアルのリンクをSliderLabelに作成する方法を示します。