As we mentioned, a component is a class that inherits from Urho.Component. This base class defines a virtual method called OnUpdate() that behaves in the same way as the Update() method on the Game class itself. This allows us to add logic to the component so that it can modify the state of the node it belongs to.
Let's create the rotate component by going through the following steps:
- In the WhackABox project root, create a new class called Rotator.cs.
- Add the following code:
using Urho;
namespace WhackABox
{
public class Rotator : Component
{
public Vector3 RotationSpeed { get; set; }
public Rotator()
{
ReceiveSceneUpdates = true;
}
protected override void OnUpdate(float timeStep)
{
Node.Rotate(new Quaternion(
RotationSpeed.X * timeStep,
RotationSpeed.Y * timeStep,
RotationSpeed.Z * timeStep),
TransformSpace.Local...