I’m helping code something similar to a scrabble game and have been having trouble with the GUI. What I want to happen is when I collect a letter in the game it will show up on the GUI and if I collect subsequent letters they will also show up on the GUI in a specified place. I already know the place I want them to be but I’m wondering how I can add textures to the GUI during runtime. So far I have the basic GUI being drawn with box’s.
void OnGUI(){
if(scrabbleTile != null)
GUI.DrawTexture(new Rect((Screen.width - 600) / 2, Screen.height - 100, 50, 50), scrabbleTile);
GUI.Box(new Rect((Screen.width - 600) / 2, Screen.height - 100, 50, 50), "");
GUI.Box(new Rect((Screen.width - 500) / 2, Screen.height - 100, 50, 50), "");
GUI.Box(new Rect((Screen.width - 400) / 2, Screen.height - 100, 50, 50), "");
GUI.Box(new Rect((Screen.width - 300) / 2, Screen.height - 100, 50, 50), "");
GUI.Box(new Rect((Screen.width - 200) / 2, Screen.height - 100, 50, 50), "");
GUI.Box(new Rect((Screen.width - 100) / 2, Screen.height - 100, 50, 50), "");
GUI.Box(new Rect((Screen.width - 0) / 2, Screen.height - 100, 50, 50), "");
GUI.Box(new Rect((Screen.width + 100) / 2, Screen.height - 100, 50, 50), "");
GUI.Box(new Rect((Screen.width + 200) / 2, Screen.height - 100, 50, 50), "");
GUI.Box(new Rect((Screen.width + 400) / 2, Screen.height - 100, 50, 50), "");
}
You can see that I’m using the GUI.DrawTexture function if the scrabbleTile(texture I want to be drawn) is not null. Well this doesn’t work for me because OnGUI() redraws this texture every frame so what happens is when a second letter is collected the first letter is overwritten with the old one. I want it to be drawn next to the old one and keep the old one. For this too happen I would have to keep this drawtexture function and add another one for each letter that is collected with the right positioning, however I’m not sure how to do this since it’s all happening during runtime. Here are some pictures for reference.