To add boxes to a plane, we need to add a method to do so. This method is called AddBox(). Let's set this up by going through the following steps:
- In the WhackABox project, open the Game.cs file.
- Add the random property to the class (preferably at the top, but anywhere in the class will work).
- Add the AddBox() method anywhere in the class, as shown in the following code block:
private static Random random = new Random();
private void AddBox(PlaneNode planeNode)
{
var subPlaneNode = planeNode.GetChild("subplane");
var boxNode = planeNode.CreateChild("Box");
boxNode.SetScale(0.1f);
var x = planeNode.ExtentX * (float)(random.NextDouble() -
0.5f);
var z = planeNode.ExtentZ * (float)(random.NextDouble() -
0.5f);
boxNode.Position = new Vector3(x, 0.1f, z) +
subPlaneNode.Position;
var box = boxNode.CreateComponent<Box>();
box.Color = Color.Blue;
}
The static random object that we create will be used...