Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class Textwrap : MonoBehaviour {
- public string theText = "Hello world blah-dy-blah!";
- public float theWidth = 2f;
- private TextMesh texty;
- // Use this for initialization
- void Start () {
- texty = GetComponent<TextMesh>();
- }
- // Update is called once per frame
- void Update () {
- string proposedString = "";
- string workingString = "";
- string[] words = theText.Split(' ');
- for (int i=0; i<words.Length; i++){
- string spacer = " ";
- if (i==0) spacer = "";
- proposedString = workingString + spacer + words[i];
- texty.text = proposedString;
- if (texty.renderer.bounds.size.x > theWidth && i>0){
- proposedString = workingString + "\n" + words[i];
- }
- workingString = proposedString;
- texty.text = workingString;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment