Last active
February 22, 2016 18:00
-
-
Save Piwly/221423ae2e8056a996c2 to your computer and use it in GitHub Desktop.
Boom?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEngine.UI; | |
using System.Collections; | |
public class BoomGoesText : MonoBehaviour { | |
private Text text; | |
void Start () { | |
if (!GetComponent<Button> ()) | |
this.gameObject.AddComponent<Button> (); | |
GetComponent<Button> ().onClick.AddListener (delegate {Boom();}); | |
} | |
// Update is called once per frame | |
void Update () { | |
} | |
public void Boom() | |
{ | |
text = GetComponent<Text> (); | |
for (int i = 0; i < text.text.Length; i++) | |
{ | |
string substringed = text.text.Substring (i, 1); | |
if (substringed != "") { | |
GameObject go = new GameObject(); | |
RectTransform rect = go.AddComponent<RectTransform> (); | |
BoxCollider2D col = go.AddComponent<BoxCollider2D> (); | |
Text t = go.AddComponent<Text> (); | |
Rigidbody2D rigid = go.AddComponent<Rigidbody2D> (); | |
Outline outline = go.AddComponent<Outline> (); | |
t.font = text.font; | |
go.transform.SetParent (this.transform.parent); | |
rect.localScale = new Vector3 (1, 1, 1); | |
t.fontSize = text.fontSize; | |
t.alignment = text.alignment; | |
col.size = new Vector2 (text.fontSize - 5, text.fontSize - 5); | |
t.text = substringed; | |
rigid.AddForce (new Vector2 (Random.Range (0, 360) , Random.Range (0, 360)) * 4, ForceMode2D.Force); | |
} | |
} | |
this.gameObject.SetActive (false); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment