I feel kinda dumb asking this, but is there anyway to center a rect based on how long the sentence is?
Here is my script so far
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class TextScript : MonoBehaviour {
public bool onLoad = false;
[HideInInspector]public bool isLoaded = false;
public string Text = "test of how long this sentence can be before it uncenters";
private GUIStyle guiStyle = new GUIStyle();
private void Start()
{
StartCoroutine(Wait());
OnGUI();
if (onLoad)
{
isLoaded = true;
}
}
private void OnGUI()
{
guiStyle.fontSize = 20;
guiStyle.normal.textColor = Color.white;
if (onLoad)
{
if (isLoaded)
{
GUI.Label(new Rect(Screen.width / 2, Screen.height - 50, Screen.width, Screen.height), Text, guiStyle);
}
}
}
IEnumerator Wait()
{
yield return new WaitForSeconds(5);
isLoaded = false;
}
}
If i play the scene, the text doesn’t center with the rect. How do i figure this out?
Oh and this is unity GUI.label, not GUIText.