[SOLVED]GUIStyle Word Wrap Check

Hey everyone!

I have custom GUIStyle set up to use wordwrap and I was wondering if there is anyway to check to see if a Label gets wrapped so it will move the next label below it out of the way.

I want to maintain good spacing between the lines that get displayed. Am I going about this the wrong way?

Here is an example of my issue:

Here is my code if that helps at all!

        GUI.Label(new Rect(Screen.width/1.9f, hieght, 400, 30),question1, Question);

        GUI.Label(new Rect(Screen.width / 1.9f, hieght + 50, 500, 50), answer1, Answer);

        GUI.Label(new Rect(Screen.width / 1.9f, hieght + 150, 500, 50), question2, Question);

        GUI.Label(new Rect(Screen.width / 1.9f, hieght + 200, 500, 50), answer2, Answer);

        GUI.Label(new Rect(Screen.width / 1.9f, hieght + 300, 500, 50), question3, Question);

        GUI.Label(new Rect(Screen.width / 1.9f, hieght + 350, 500, 50), answer3, Answer);

Thanks for looking!

EDIT: Final Code

void OnGUI()
    {
        GUI.skin = Skin;
        GUIStyle Question = Skin.customStyles[0];
        GUIStyle Answer = Skin.customStyles[1];
        

        if (isOn == true)
        {

            string question1 = getQuestion1();
            string question2 = getQuestion2();
            string question3 = getQuestion3();
            string answer1 = getAnswer1();
            string answer2 = getAnswer2();
            string answer3 = getAnswer3();
            hieght = (Screen.height / 4);
            GUILayout.BeginArea(new Rect(Screen.width / 1.9f, hieght, 400, 1000));
            //GUI.BeginGroup(new Rect(Screen.width/1.9f, hieght, 100, 100));
            GUILayout.Label(question1, Question);
            GUILayout.Space(10);
            GUILayout.Label(answer1, Answer);
            GUILayout.Space(30);
            GUILayout.Label(question2, Question);
            GUILayout.Space(10);
            GUILayout.Label(answer2, Answer);
            GUILayout.Space(30);
            GUILayout.Label(question3, Question);
            GUILayout.Space(10);
            GUILayout.Label(answer3, Answer);
            GUILayout.EndArea();
            //GUI.EndGroup();
        }

You can use the GUIStyle.CalcHeight function for this:

I’m assuming that the variable ‘Answer’ is your GUIStyle and ‘answer1’ is your string. You can figure out the different sizes of the typed in text something like this:

float oneLineHeight = Answer.CalcHeight(new GUIContent(""), 500);
float answerHeight = Answer.CalcHeight(new GUIContent(answer1), 500);