Hi
How would i increase ‘Label’ size with increased text content ?
to achieve this i guess i need to know how many lines of text are there, but how will i know that ? please share if you have any ideas.
Hi
How would i increase ‘Label’ size with increased text content ?
to achieve this i guess i need to know how many lines of text are there, but how will i know that ? please share if you have any ideas.
Hi guys, i worked out a solution for my problem its not perfect but its ok for now, i am posting my script so you can test and add any suggestions to make it better.
using UnityEngine;
using System.Collections;
public class DynamicGUI : MonoBehaviour {
public float dynamicHeight;
public GUIStyle mystyle;
public string content;
public string dymmyText;
private float wide;
private float tall;
private string mycontent = "The best place to ask and answer questions about development with Unity. To help users post good questions and use the site effectively we have posted a user guide.";
// Use this for initialization
void Start () {
wide = Screen.width;
tall = Screen.height;
}
void OnGUI() {
GUI.Box(new Rect(5,0,Screen.width-10,dynamicHeight),content,mystyle);
if(GUI.Button(new Rect(0,Screen.height-50,Screen.width,50),"Click")) {
content = GetString(mycontent);
}
}
public string GetString( string value ) {
string finalString = "";
int n = -1;
for(int i = 0; i < value.Length; i++){
n++;
// n is the character count, at res 320*480 its 33 char in a single line (wide*.103125f = 33)
if(n >= (wide*.103125f) ){
finalString+=value*+"
";*
_ dynamicHeight+=wide*.084375f;_
n = -1;*
print("newline");*
_ }else if(value == ’ '){_
* print (“space”);*
* finalString+=" ";*
* }else{*
_ finalString+=value*;
}
}*_
* return finalString;*
* }*
}
This is how it looks on single click
[60570-screen-shot-2015-12-24-at-10855-pm.png|60570]
This is how it looks when i incremented the text content by double clicking the button.
[60571-screen-shot-2015-12-24-at-10934-pm.png*|60571]*
What i did is, in a fixed resolution 320*480, i am checking the maximum number of character can fit in a single line, if that number is achieved than i am incrementing the dynamicHeight variable, which is my height for the GUI Box, with that i am also adding a new line to my final text.
I know this is not perfect but if you guys have any solution please do let me know.
*
*