Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- string WrapText(string textToWrap, float width)
- {
- string returnText = "";
- string line = "";
- int lastSpace = 0;
- for (int i = 0; i < textToWrap.Length; i++)
- {
- if (line.Length == 0 && textToWrap[i] == ' ')
- continue;
- line += textToWrap[i];
- if (line[line.Length-1] == ' ')
- lastSpace = line.Length-1;
- textMesh.text = line;
- //Debug.Log("width: " + textMesh.renderer.bounds.extents.x);
- if (textMesh.renderer.bounds.extents.x * textMesh.transform.lossyScale.x > width)
- {
- string leftOver = line.Substring (lastSpace+1, line.Length - (lastSpace+1));
- line = line.Substring(0, lastSpace);
- returnText += line + "\n";
- line = leftOver;
- lastSpace = 0;
- }
- }
- if (line != "")
- returnText += line + "\n";
- textMesh.text = "";
- return returnText;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement