Sitemap

Grab a List- C# Skill in Unity: 6

2 min readSep 30, 2021

Objective: get to know about the basic of list in C#.

Press enter or click to view image in full size
Photo by Kelly Sikkema on Unsplash

List is a function that similar to array but available to add and remove a new item, or doing any other actions during runtime.

Take an example from RPG game, array can be used to fixed numbers of item such as inventory. List can be used to the whole item library due to its flexibility.

How to use list

List can be created as a variable and readjusted in editor.
To create a list, you need to declare a type to it.

Press enter or click to view image in full size

Then we can add some elements by using List.Add(item), and pass it the value that match the type.

If you want to insert an value to a specific position or index, just use List.Insert(int, item).

Press enter or click to view image in full size

We can also remove some elements that we do not need by using List.Remove(item). You can use the value or index to locate the specific element.

The last, to remove the whole list, we can use List.Clear() to clear everything.

List is very similar to array but with more functionality and usage in program.
That is pretty much everything you need to know about the list of Unity.

--

--

S.J. Jason Liu
S.J. Jason Liu

Written by S.J. Jason Liu

A passionate gamer whose goal is to work in video game development.

No responses yet