Guest User

Untitled

a guest
Apr 30th, 2013
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Textwrap : MonoBehaviour {
  5.  
  6. public string theText = "Hello world blah-dy-blah!";
  7. public float theWidth = 2f;
  8.  
  9. private TextMesh texty;
  10.  
  11. // Use this for initialization
  12. void Start () {
  13. texty = GetComponent<TextMesh>();
  14. }
  15.  
  16. // Update is called once per frame
  17. void Update () {
  18.  
  19. string proposedString = "";
  20. string workingString = "";
  21.  
  22. string[] words = theText.Split(' ');
  23. for (int i=0; i<words.Length; i++){
  24.  
  25. string spacer = " ";
  26. if (i==0) spacer = "";
  27.  
  28. proposedString = workingString + spacer + words[i];
  29.  
  30. texty.text = proposedString;
  31. if (texty.renderer.bounds.size.x > theWidth && i>0){
  32. proposedString = workingString + "\n" + words[i];
  33. }
  34.  
  35. workingString = proposedString;
  36. texty.text = workingString;
  37.  
  38. }
  39.  
  40.  
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment