C# Arrays Practical Example

Tyler Henry
Sep 2, 2022

Objective: Changing the color of cubes in an Array with a foreach loop

Alrighty so when making a game we want to see a practical application of what we have been learning about Arrays in a loop or in this case a For Each Loop.

As you can see, we can make an array using game objects like the cubes we will be using which will be quite useful. Then we have our if statement which uses the Input of the space key. Then for each loop is using the cubes in the array and we are changing the color to red.

We have to add the cubes to the inspector first before anything will work.

Here are the cubes in action from our Array.

--

--