-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TextGenerator.cs
50 lines (44 loc) · 1.36 KB
/
TextGenerator.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
public class TextGenerator : MonoBehaviour
{
public Sprite[] Fontface;
public string Text;
public SpriteRenderer TextCharacter;
// Start is called before the first frame update
void Start()
{
GenerateText(Text);
}
// Update is called once per frame
void Update()
{
}
public void GenerateText(string text)
{
if(text != null) {
Text = text;
int column = 0;
foreach(char ch in Text) {
if(Char.IsDigit(ch)) {
GenerateChar(Fontface[ch - '0'], column);
} else if(char.IsLetter(ch)) {
char chu = char.ToUpper(ch);
GenerateChar(Fontface[chu - 'A' + 10], column);
} else if(ch == '.' || ch == ',') {
GenerateChar(Fontface[36], column);
} else if(ch == ':') {
GenerateChar(Fontface[37], column);
}
++column;
}
}
}
void GenerateChar(Sprite sprite, int column) {
GameObject o = Instantiate(TextCharacter.gameObject, transform);
o.transform.localPosition = new Vector3(column*10, 0, 0);
o.GetComponent<SpriteRenderer>().sprite = sprite;
}
}