Book Image

Mastering Unity Scripting

By : Alan Thorn
Book Image

Mastering Unity Scripting

By: Alan Thorn

Overview of this book

Table of Contents (17 chapters)
Mastering Unity Scripting
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Lists and collections


Perhaps, the most common task when programming games is to store lists of data. The nature of this data varies tremendously: high scores, player stats, enemy stats, inventory items, weapons, power-ups, level lists, and more. Wherever possible, choose static arrays to hold data due to their speed and efficiency. Static arrays were considered in detail in Chapter 1, Unity C# Refresher. In short, static arrays are created ahead of time, and their maximum capacity is fixed from the outset. Items can be added and removed from them at runtime, but their total size can never change. If their maximum capacity is not utilized, then space would be wasted. Static arrays, as their name implies, are an excellent choice for storing lists of data that remain constant, such as all levels in the game, all weapons that can possibly be collected, all power-ups that can possibly be collected, and so on.

However, you'll often need dynamic arrays, which can grow and shrink in capacity to...