You can do that with 2D textures or 3D objects. 2D is easier, because you can think in terms of screen coordinates - you can use an array of textures and the GUI system. 3D is more complicated, but allows more special effects. I’ll give you some hints about the 2D version, and you can in the future extend them to a 3D version.
The character graphics: you could create a public Texture2D array letters in the script, and populate it in the Inspector with the textures so that letter[0] is “A”, letter[1] is “B” and so on - this helps finding a given letter’s texture by its ASCII code:
public Texture2D[26] letters; // drag the textures orderly here
// this function returns the texture corresponding to the letter:
Texture2D GetLetter(char letter){
return letters[(int)letter - (int)'A'];
}
The words: you could create a public array of strings and populate it in the Inspector, like in the graphics case:
public string[] words;
char and string are different things in C#, thus you must use functions to convert from one to the other when necessary. If you want to “print” some word with your letters, for instance, you can use something like this:
string curWord = "Hello"; // word to print
Vector2 pos = new Vector2(10,10); // where to draw the word
int charWidth = 40; // fixed character width
int charHeight = 60; // character height
int charSpace = 5; // space between characters
void OnGUI(){
char[] chars = curWord.ToCharArray();
Rect r = new Rect(pos.x, pos.y, charWidth, charHeight);
foreach (char c in chars){
GUI.DrawTexture(r, GetLetter(c)); // draw the letter c
r.x += charWidth + charSpace; // advance screen position
}
}
NOTE: GUI items are rendered in the function OnGUI. This function is called automatically by the system - don’t call OnGUI yourself, just create the function!
If you want to display clickable letters, use GUI.Button instead:
foreach (char c in chars){
if (GUI.Button(r, GetLetter(c))){
// the character c was clicked! do whatever
// you have to do with it here
}
r.x += charWidth + charSpace; // calculate next char position
}