Posts

Showing posts from May, 2017

How different data structures can be used in game coding: List, Queue, and Stack

I'm sure most game creators are familiar with an array to store data, the problem with an array is once the size is set, it becomes much more difficult to manage. There are times when you want to sort, add, or remove data. The best way to do this is using different types of Data Structures. I'm going to focus on Lists, Queues, and Stacks though there are several others. *This article assumes you have a basic understanding of  Generic types. Some sample code to learn and play around with. hopefully the comments are useful: using System.Collections; using System.Collections.Generic; using UnityEngine; public class DataStructuresScript : MonoBehaviour { string[] arrayString = new string[] { "Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten" }; List<string> listString = new List<string>(); Queue<string> q

Adding randomness to your game through code using Unity 3d

There are several different ways to add randomness through code. I'm going to mostly talk about the built in random number generators and examples of where to use them. But first I will touch on why it is also important to understand the statistics of a random number generator. *I'm going to reuse the word number when describing randomness, however what the number represents can be anything. Such as a random color(RGBA hex code) or choosing a random texture from an array.* Randomness can be used in several ways. Two of the most common are below.  Example 1 . Where any number is used regardless of the previous. Example: When using 1-10 at ten iterations any number is used. So there can be three 1's, four 2's, zero 3's,... This is achieved simply using Unity's Random.Range() or System.Random.Next(). The statistics of example 1 : Each number may or may not be used equally and every number within the constraints may or may not be used. Example output at t