View difference between Paste ID: kGvE1y3s and ufF653px
SHOW: | | - or go back to the newest paste.
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
11+
12
		texty = GetComponent<TextMesh>();
13
	}
14
	
15
	void Update () {
16-
	// Update is called once per frame
16+
17
		texty.text = "";
18
		string[] words = theText.Split(' ');
19-
		string proposedString = "";
19+
		for (int i = 0; i < words.Length; i++){
20-
		string workingString = "";
20+
21
			string workingString = texty.text;
22
			texty.text = workingString + " " + words[i];
23-
		for (int i=0; i<words.Length; 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-
			string spacer = " ";
25+
26-
			if (i==0) spacer = "";
26+
27
}