How to do it...

We will build a simple class as follows:

  1. Create the RandomGaussian class, as shown in the following code:
using UnityEngine; 
 
public class RandomGaussian 
{ 
    // next steps 
} 
  1. 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 
} 
  1. 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); 
} 
  1. Then, sum all the values, as shown in the following code:
for (i = 0; i < values.Length; ...

Get Unity 2018 Artificial Intelligence Cookbook - Second Edition 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.