- Home /
How can i create [n] prefabs taking Array data?
I have a table in a local database which contains a mini-Market Stock data .svc inport.
I need to take all the database information, and set it in a unity table.
I want to create a prefab containing 4 text-fields and setting the database info in those fields, and create 1 prefab for each array(there is 1 array for each line on the database)
Here is my script
public string[] items;
// Use this for initialization
IEnumerator Start ()
{
WWW itemsData = new WWW ("http://localhost/inventario_iraule/Leer_Stock_Ropa_2016.php");
yield return itemsData;
string itemsDataString = itemsData.text;
//print (itemsDataString);
items = itemsDataString.Split (';');
for (int i = 0; i < items.Length; i++)
{
print (GetDataValue (items [i], "Rotulos_fila:"));
}
}
string GetDataValue(string data, string index)
{
string value = data.Substring (data.IndexOf (index) + index.Length);
if(value.Contains("|"))value = value.Remove (value.IndexOf ("|"));
return value;
}
Okey, i get all the data, and i have a index to search about specific data, but.. i don't know how to continue with these..
expected that the solution was creating 1 Php file for each column in the database, for filter all the information, but i'm sure there's a easier way to do it.
My objective is to show all the database info organized in unity. And i don't know how to "separate" the whoole array in a lot of game-objects(prefabs) or Text-fields.
Thank you so much for reading.
Hope someone can help me
I'm not quite understand what is your problem.
So atm you can get all info from db, what do you want to do with them?
Fill them into 4 textfields like :
$$anonymous$$enu 1 : X , Y , Z , W $$anonymous$$enu 2 : A, B , C, D
Is that what you want?
What about A prefab for each array? I don't understand....
If you can use $$anonymous$$mviewer, it would be easier for me to help you.
Thanks for your help men, I have already solved my problem. But as you know is a world full of problems that you have to face, we will read again :P
Answer by Deliboyz · Jan 25, 2017 at 09:09 AM
public Text Textbox;
public Transform DesiredTransform;
for(int i = 0; i < items.Length; i++)
{
Text TextElement = Instantiate(Textbox) as Text;
TextElement.transform.SetParent(DesiredTransform);
TextElement.text = items[i];
}
Thank you very much broo', so quick answer,
That's exactly what i was looking for!
I'm working so hard with this, and You helped me take another step!
Sorry for my bad English xD