How do i display all my arrays in string? It only shows one.

Hello. I wanted to try to display my array prices in the game using the Example: showPrices.text ethod. It works but it only shows 1 of my arraylist. May i know how am i able to show all? My console seems to have printed the arrays. I want the same to be display as my in game. I have attached a pic so you guys can look at the problem clearly.

Here is my code

public class IngredientShop : MonoBehaviour
{
public string[ ] Ingredient = newstring[6];
public float[ ] Prices = newfloat[6];
public Text shopPrices;
inti=0;
//Usethisfor initialization
private void Start()
{
for(i=0;i<Prices.Length;i++)
{
Prices[0]=1.20f;
Prices[1]=0.90f;
Prices[2]=1.80f;
Prices[3]=1.60f;
Prices[4]=1.30f;
shopPrices.text=Ingredient_+“\t”+Prices*;_
Debug.Log(Ingredient_+“\t”+Prices);
}
}

*_

have you set up the Text so it has Vertical overflow?

Hi, yes i just changed it. No difference. No changes.

what about replacing \t with \n?

Also you should use code tags when posing, it’s easier to read :stuck_out_tongue:

i also did change the \t with \n . no difference hahahaha. oh my. Idk why but i hate tags hahah. The fact that im unsure on how to use it on this arrays hahaha. Right now, i need to know how to get the display working haha

Try changing

shopPrices.text=Ingredient+"\t"+Prices;

To

shopPrices.text=Ingredient+"\t"+Prices[i];

and weird, I just tried using \n and it worked in unity 5.3.1 :open_mouth:

im using 5.3.5f hahaha

Btw, did what you said. There’s no difference. Is it cool if i see yours?

Sorry I’ve just headed out and am away from computer, however a quick but inefficient fix is removing the forloop completely and using below

shopPrices.text =  Prices[0].ToString() + "\n" + Prices[1].ToString() + "\n" + Prices[2].ToString() + "\n"
            + Prices[3].ToString() + "\n" + Prices[4].ToString() + "\n" + Prices[5].ToString() + "\n";

Okay that solves the problem. However, i hope to get the script with the forloop working :confused: If you know the efficient fix, hope you can share it with me :slight_smile: Thanks for you time mate!

Soon as i’m back at my place will slap the other one on here! :slight_smile:

you could try something like this

string tempString = "";
for (int i = 0; i < Prices.Length; i++) {
    tempString += string.Format("{0}\n", Prices[i]);
}
shopPrices.text = tempString;

ITS WORKING!!! THANKS PASSER! one note, may i know what does {0} means?

the “{0}” is a placeholder for string.Format() to use

the first argument of string.Format(), is the string you are formatting, and the 2nd argument is what to replace {0} with. If i had a {1}, {2} etc i would be able to provide more arguments that it can replace with.

this is just my preference since i find it is cleaner than adding strings with +, and that it automatically calls .ToString() on anything you pass in.

tempString += "/n" + Prices[i];

would be the same result