Hi, so the functionality I’m trying to get is:
Foreach stock
- Grab the info
- Instantiate the prefab
- Stock count + 1
- Repeat but set the space in between the prefab the divider amount.
So for the first stock, it’d be in the starting list place.
The second stock would be -15 under,
The third stock would be -30 under.
The issue is…when it starts, it sets all of the prefabs into one position and moves
Here’s the code
public void initializeStocks()
{
foreach (Stock st in su.stocks)
{
var valueEquation = st.price * st.shares;
var dividerAmount = stockCount * -15;
// Gets child components of Prefab in order & sets their value to the stock value
stockObject.transform.GetChild(0).gameObject.GetComponent<Text>().text = st.stockName;
stockObject.transform.GetChild(1).gameObject.GetComponent<Text>().text = st.price.ToString();
stockObject.transform.GetChild(2).gameObject.GetComponent<Text>().text = st.changeInPrice.ToString();
stockObject.transform.GetChild(3).gameObject.GetComponent<Text>().text = st.shares.ToString();
stockObject.transform.GetChild(4).gameObject.GetComponent<Text>().text = valueEquation.ToString();
Vector2 newPos = new Vector2(transform.position.x, dividerAmount);
stockObject.transform.position = newPos;
Instantiate(stockObject, transform);
stockCount++;
}
}
Hopefully, I explained what’s going on well enough. Not sure what to do as this is the first time I’ve had to create a list like this.
Any help is appreciated ![]()
