- Home /
Question on for loop with array
I'm new to C# programming and I'm trying to create a script that will simulate stacks of money growing. I'm trying to create an array of game objects and then incrementally grow them vertically and eventually tile a texture so it looks as though the stacks of money are scaling upward on a flat surface.
I created the variable "stackcount" as a representation of how many stack of money are needed. I'm having trouble figuring out how to both create the stacks and increment the height based on this variable. When I try to use the variable "stackcount" in either for loop and this does not work. Any suggestions?
public class Blockbuilder : MonoBehaviour
{
public GameObject[] blockarray;
public int arrsize = 10;
public int blockgrowth = 0;
public int stackcount = 20; //number of stacks
public int objectcount;
void Start()
{
blockarray = new GameObject[arrsize];
for (int i = 0; i < blockarray.Length; i++)
{
blockarray[i] = GameObject.Instantiate(Resources.Load("Block Prefab")) as GameObject;
blockarray[i].transform.position = new Vector3(i * 2, 1, 1);
objectcount++;
stackcount--;
}
for (int j = 0; j < blockarray.Length; j++)
{
blockarray[j].transform.localScale = Vector3.Scale(blockarray[j].transform.localScale, new Vector3(1f, blockgrowth, 1f));
objectcount++;
stackcount--;
Debug.Log(stackcount.ToString());
blockarray[j].transform.position = blockarray[j].transform.position + new Vector3(0, 1, 0); //offset adjustment
}
}
void Update()
{
if (objectcount > arrsize)
if (objectcount > objectcount + arrsize)
{
blockgrowth = blockgrowth + 2;
}
}
}
What triggers the stacks of money to grow? Is it just on a timer or is it an event?
it grows over time...event based. The amount with grow over time. Hope this helps.
Your answer
![](https://koobas.hobune.stream/wayback/20220612222141im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
comparing variables of gameobjects in an array 2 Answers
Finding the Sum of Values of Multiple GameObjects in an Array + Variable Sized arrays 0 Answers
how to check if an element has been removed from a GameObject array C# 2 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers