We will build a simple class as follows:
- Create the RandomGaussian class, as shown in the following code:
using UnityEngine; public class RandomGaussian { // next steps }
- Define the RangeAdditive member function that initializes the necessary member variables, as follows:
public static float RangeAdditive(params Vector2[] values) { float sum = 0f; int i; float min, max; // next steps }
- Next, check whether the number of parameters equals zero. If so, create three new values, as demonstrated in the following code:
if (values.Length == 0) { values = new Vector2[3]; for (i = 0; i < values.Length; i++) values[i] = new Vector2(0f, 1f); }
- Then, sum all the values, as shown in the following code:
for (i = 0; i < values.Length; ...