S
S
Sergey Klykov2016-05-04 11:09:31
Unity
Sergey Klykov, 2016-05-04 11:09:31

How to implement graphics settings in Unity3d? via UI Button?

In the unit, I set 3 graphics levels Low, Normal, High and, accordingly, 3 UI Buttons.
Through the GUI it looks like this.

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    void OnGUI() {
        string[] names = QualitySettings.names;
        GUILayout.BeginVertical();
        int i = 0;
        while (i < names.Length) {
            if (GUILayout.Button(names[i]))
                QualitySettings.SetQualityLevel(i, true);
            
            i++;
        }
        GUILayout.EndVertical();
    }
}

Well, I created a separate script and wrote public void QualitySettings.SetQualityLevel(1);
and threw it on the UI Button, but the button does not see it, tell me how to do it through Ui?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Daniil Basmanov, 2016-05-04
@DEMIGODDD

Button does not know how to call static methods, so to change graphics settings you need to write a wrapper:

using UnityEngine;

public class Test : MonoBehaviour
{
    public void SetQualityLevel(int index)
    {
        QualitySettings.SetQualityLevel(index, true);
    }
}

In the inspector it will look like this:
g2TSy

P
p4p, 2016-05-04
@p4p

Download the latest version of unity and use ugui to do it there. Elements are created as game objects.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question