#Unity Array
1 messages · Page 1 of 1 (latest)
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;
}
}
whats the problem? this should work
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
why would it get the other numbers
your setting ONE text
if you do Debug.Log(item); you will see all of them in the console
Ah okay, yeah that works. I wonder what I have to do to print it as text 
There must be a tutorial on how to print arrays out as Unity TMPro somewhere
by putting them all into 1 string and setting the text to that string