I’ve instantiated prefabs from lists many times, but I’d like to know how to do it with an array.
The array is string and the prefab is a group of text items with a script containing game objects.
public class VehicleIndexScript : MonoBehaviour
{
public GameObject ID;
public GameObject Make;
public GameObject Model;
public GameObject Year;
public GameObject Mileage;
public void DisplayVehicles(string id, string make, string model, string year, string mileage)
{
this.ID.GetComponent<Text>().text=id;
this.Make.GetComponent<Text>().text=make;
this.Model.GetComponent<Text>().text=model;
this.Year.GetComponent<Text>().text=year;
this.Mileage.GetComponent<Text>().text=mileage;
}
}
Normally, I’d run through the list, make temp variables, then display them as follows:
for(int i = 0; i< List.Count; i++)
{
GameObject brObj = Instantiate(BrakePrefab);
Brakes tmpBrake = BrakeList*;*
-
DateTime ServiceDate = tmpBrake.ServiceDate;*
-
brObj.GetComponent<BrakesScript>().DisplayBrakes("ID:" +ID, "Date of Service: " +ServiceDate, "Service Location: " +tmpBrake.Location,*
-
"Mileage: " +tmpBrake.Mileage, "Labor: " +tmpBrake.Labor, "Brake Brand: " +tmpBrake.BrakeBrand,*
-
"Brake Price: " +tmpBrake.BrakePrice, "Which Wheels: " +tmpBrake.BrakeWheels,*
-
"Brake Purchase Location: " + tmpBrake.BrakePurchaseLocation, "Brake Notes: " +tmpBrake.BrakeNotes);*
-
brObj.transform.SetParent(BrakeDisplayparent);*
-
}*
This data is coming from a WWW call, so rather than trying to convert it, I want to try to keep it as an array, unless someone knows a way to take that information and put it into a class list.
Thanks!