Time for action – selecting a pony from a List using a for loop
Let's add four pony names to a List
. Retrieve and display the number of elements in the List
. Then use a for
loop to display each pony name, and select one of them:
- Modify
LearningScript
as shown in the next screenshot. - Save the file.
- In Unity, click on Play.
What just happened?
The following screenshot shows the number of elements in ponyList
, the names of the ponies we added to ponyList
, and the pony we were looking for:
The analysis of the code is as follows:
- The code between lines 8 and ...
Get Learning C# by Developing Games with Unity 3D Beginner's Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.