Adding the Rotator component is as simple as adding any other component. Let's set this up by going through the following steps:
- In the WhackABox project, open the Game.cs file.
- Update the AddBox() method by adding the code marked in bold in the following code block:
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;
var rotationSpeed = new Vector3(10.0f, 20.0f, 30.0f);
var rotator = new Rotator() { RotationSpeed = rotationSpeed };
boxNode.AddComponent(rotator);
}
We begin by defining...