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:

  1. Modify LearningScript as shown in the next screenshot.
  2. Save the file.
  3. In Unity, click on Play.
    Time for action – selecting a pony from a List using a for loop

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:

What just happened?

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.