Prefab: Printing single letters of a word in UI Panel (one public variable different values)


I’m new to Unity and trying to make a basic Lingo game (a word missing 1 letter, so the user will have to select the right letter from the 2 options).
So I’ve made a prefab for the yellow panel and its text.

Here’s my problem:
Suppose the word is “apple” and I want every yellow panel to hold 1 char. How can I achieve that with prefab? This is my code and what I get right now is A A A A A (first letter in “apple” which is “A” is dequeued and shown in every panel…). What should I do?


using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.IO;
using System.Collections.Generic;

public class WordStack : MonoBehaviour {
	string word;
	public Text letter;

	void Start(){
		word = "apple";
		Queue<string> lettersQueue = new Queue<string>();
		foreach (char element in word){
			lettersQueue.Enqueue (element.ToString().ToUpper());
		letter.text = lettersQueue.Dequeue();

	 void Update(){


I can’t really tell how this code relates to the rest of your project, but if this is the script that is attached to your prefab, it makes sense that it only ever gives you “A”, because after Enqueueing all the letters, you only Dequeue once, which always returns the first item in your Queue.

Here’s an idea; Create a script on your prefab which has a public variable called “letter”. In the Start function, all you do is display that letter.

Generating the prefabs, each with its own letter, is not a job that should be done by each indivudual letter-prefab. Rather, you could make another object with a script on it that instantiates these prefabs.

I can’t really tell how this code relates to the rest of your project

Could you please elaborate a bit? Honestly I’m quite puzzled about the flow of a typical program in Unity.

I’d really appreciate it if you could help me get the bigger picture of how this should be done ideally.
Thank you