Implementing the cursor code

Do a build in Unity and move it to Visual Studio. It is time to write some code again. We need to move the cursor object in the Update() method. This is the code:

private void Update() {     if (cursor == null)         return;     var camTrans = Camera.main.transform;     cursor.position = camTrans.position + camTrans.forward*maxDistance;     cursor.up = camTrans.up; } 

First, we check whether we actually have a cursor. It would be pointless to do anything when we have no object to draw.

Then, we take the position of the main camera. To do this, we can use the static property main in the Camera class--this will return the camera. This has a transform property that tells us all about the position and rotation. We take this position ...

Get Microsoft HoloLens Developer’s Guide 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.