#Unity Array

1 messages · Page 1 of 1 (latest)

hollow depot
#

I still don't get it it works in Console app```cs
int[] rannum = new int[3];
rannum[0] = 0;
rannum[1] = 1;
rannum[2] = 2;

foreach (var item in rannum)
{
Console.WriteLine(item);
}

but in unity I would imagine I should do something like this but no...
```cs
    [SerializeField] TextMeshProUGUI num;
    void Start()
    {
        int[] rannum = new int[3];
        rannum[0] = 0;
        rannum[1] = 1;
        rannum[2] = 2;

        foreach (var item in rannum)
        {
            num.text = item;
        }
    }
quiet path
#

whats the problem? this should work

hollow depot
#

It dosen't work Cannot implicitly convert type 'int' to 'string'
So I did this ```cs
foreach (var item in rannum)
{
num.text = item.ToString();
}
}

Now I get zero errors but it only prints 2, not the other numbers
quiet path
#

your setting ONE text

#

if you do Debug.Log(item); you will see all of them in the console

hollow depot
#

Ah okay, yeah that works. I wonder what I have to do to print it as text aPES_Think
There must be a tutorial on how to print arrays out as Unity TMPro somewhere

quiet path