Adding a camera is a straightforward process, as shown in the following steps:
- In the WhackABox project, open the Game.cs file.
- Add the camera property to the class, as shown in the following code snippet. A good practice is to place it right after the declaration of the class.
- Add the InitializeCamera() method anywhere in the class, as shown in the following code snippet:
private Camera camera;
private void InitializeCamera()
{
var cameraNode = scene.CreateChild("Camera");
camera = cameraNode.CreateComponent<Camera>();
}
In UrhoSharp, everything is a node, just as everything is a GameObject in Unity, including the camera object. We create a new node, which we call camera, and then we create a Camera component on that node and keep the reference to it for later use.