Deozaan

Textwrap.cs

Apr 30th, 2013
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.     void Start () {
  12.         texty = GetComponent<TextMesh>();
  13.     }
  14.    
  15.     void Update () {
  16.        
  17.         texty.text = "";
  18.         string[] words = theText.Split(' ');
  19.         for (int i = 0; i < words.Length; i++){
  20.            
  21.             string workingString = texty.text;
  22.             texty.text = workingString + " " + words[i];
  23.             if (i==0) texty.text = workingString + words[i];
  24.             if (texty.renderer.bounds.size.x > theWidth && i > 0) texty.text = workingString + "\n" + words[i];
  25.         }
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment