Bata Kos
Bata Kos

Reputation: 85

How to get items from array by order

How can I take text from array and put it by order in my text. For now my text only shows last item in array.

Here is the code:

void Start()
{
    this.gameObject.GetComponent<MeshRenderer>().sortingLayerName = "Foreground";
    textMesh = GetComponent<TextMeshPro>();

    for (int i = 0; i < slova.Length; i++)
    {
        string value = slova[i];

        textMesh.text = value;
        int random = Random.Range(0, slova.Length);
    }
}

Upvotes: 0

Views: 64

Answers (2)

janmbaco
janmbaco

Reputation: 350

You should use a linq instruction like

void Start()
{
 this.gameObject.GetComponent<MeshRenderer>().sortingLayerName = "Foreground";
 textMesh = GetComponent<TextMeshPro>();
 textMesh.text = string.Join(" ", slova);
}

something like this:

enter image description here

Upvotes: 1

Robert Wolf
Robert Wolf

Reputation: 301

I don´t know what you want to achieve. But if you want that textMesh.text should be appended with value, than you should use the following

textMesh.text += slova[i];

Upvotes: 0

Related Questions