Objective: understand return arrays and how to use them.
The next return to learn is a return array. It is what it sounds like. It a function that returns an array and in this tutorial, I’ll show you how to set them up for your program.
We are going to create a program that randomly selects a starting position. To begin we need to create an array of 5 different position and create a custom method to generate a random index. then use a custom method to set the position to that sub index.
we need to create a public array of vector3.
Fill out 5 positions in the inspector.
Create a custom method to generate a random index.
Create a custom return function
In void start we want to set the random index to the get random method.
We then use a custom method to set the position to that sub index
Create a vector3 return function.
Alternatively, we could use parameters.
in the void start method, we set the position to the random index.
Now, when you start the program, the starting position will be randomly selected from the array of position you created using the return array. Don’t be afraid to experiment with your code, and I’ll see you in the next tutorial.