© Rakesh Baruah 2020
R. BaruahVirtual Reality with VRTK4 https://doi.org/10.1007/978-1-4842-5488-2_6

6. Controller Button Inputs as Actions

Rakesh Baruah1 
(1)
Brookfield, WI, USA
 

So far, we’ve set up virtual cameras in our scene that connect to the user’s head-mounted display. We’ve also added interactive game objects to our scene and wired them up to user input through the keyboard. But this is VR. We’re not here to use keyboards. We want to use touch controllers.

Keyboards are old school, but coordinating user input through VR applications, which are very much new school, can be challenging to the point of frustration. In this section we are going to build on our Cake Calculator Unity project to add input management through VRTK. Through a series of steps, we will transform our Cake Calculator into an application that accepts user input through both the keyboard and our VR controllers.

In this chapter you will learn how to do the following:
  • Install a third-party VR SDK.

  • Add a third-party VR camera rig to a scene.

  • Use the VRTK TrackedAlias game object.

  • Use the VRTK Button Action component.

  • Connect VR controllers to VRTK controller prefabs.

  • Create VRTK proxy actions.

  • Chain actions using the VRTK Boolean action component.

VR SDK Integration Packages

Before we move on, there’s a little bit of housekeeping I need to address. So far, we have limited our engagement with our VR hardware to the head-mounted display. In the following section we will begin connecting our VR controllers to the VRTK interface. To do this, you must download and install the Unity integration package for your device from the Unity Asset Store. Read more about the requirements of your VR SDK in the Unity online manual.

The Tracked Alias

As a framework, VRTK provides a library of prepackaged objects and functions that simplify our prototyping tasks in Unity. The UnityXRCameraRig is an example of a VRTK prefabricated game object that acts as a layer between us and the complexity of Unity’s inner workings. Another such game object is VRTK’s TrackedAlias prefab.

The purpose of the VRTK Tracked Alias game object is to coordinate two or more inputs that execute the same event. In Chapter 5, we created an event handler through the built-in Unity Input class. In this chapter, we perform the same action. However, instead of passing a user’s keystroke into the Unity Input System, we will pass the press of a button on a touch controller.

Step 1: Drag and Drop the Tracked Alias Prefab into the Hierarchy

If you created a project for the original Interest Calculator exercise, then for this exercise you can simply copy Scene1 and rename it Scene2. A keyboard shortcut to copy an asset is to highlight it in your Project window and press Ctrl+D. Once you’ve created a duplicate, double-click Scene2 to open it in the Hierarchy window.

After we’ve saved our new scene and confirmed the installation of our integration package, we must import the VRTK Tracked Alias object into our scene. In the Project window, select Assets ➤ VRTK ➤ Prefabs ➤ CameraRig ➤ TrackedAlias ➤ TrackedAlias (Figure 6-1). The VRTK TrackedAlias game object acts as a mediator between us and Unity’s Input Manager. I like to think of the TrackedAlias game object like a power strip or USB hub. It’s a single object into which we can plug different wires to execute the same task.
../images/488645_1_En_6_Chapter/488645_1_En_6_Fig1_HTML.jpg
Figure 6-1

VRTK includes a TrackedAlias prefab game object to help coordinate between scripts and XR inputs

Step 2: Connecting Our Touch Controllers to VRTK

Because we turned on VR support for our project in the Unity Project Settings when we began the Interest Calculator exercise, the SDK for our VR headset is already running in our scene. Now, we can use the VRTK TrackedAlias object to connect our controllers to our Unity scene. To do this we simply need to add the VRTK Interactor prefab as a child object of our TrackedAlias object in the Scene Hierarchy.

Navigate to the VRTK Interactor prefab in the Project window: Assets ➤ Prefabs ➤ Interactions ➤ Interactors ➤ Interactor (Figure 6-2). Drag and drop the Interactor object from the Project window into the Scene Hierarchy as a child of both the LeftControllerAlias child game object and RightControllerAlias child game object beneath the Aliases game object within the TrackedAlias game object (Figure 6-3).
../images/488645_1_En_6_Chapter/488645_1_En_6_Fig2_HTML.jpg
Figure 6-2

VRTK’s Interactor prefabs provide a quick way to track a user’s hand movements

../images/488645_1_En_6_Chapter/488645_1_En_6_Fig3_HTML.jpg
Figure 6-3

Add the VRTK Interactor prefabs to the TrackedAlias to track left and right controller movement

Step 3: Importing an SDK-Specific Virtual Camera Object

Until now, we’ve relied on the UnityXRCamera rig as our interface for a virtual camera. However, now that we have introduced SDK-specific touch controllers (specific, in my case, to the Oculus Rift) we must bring our SDK’s camera object into the scene.

Beyond the UnityXRCameraRig

If you’re asking yourself why the UnityXRCameraRig game object can’t continue to serve as a surrogate for our head-mounted display, it might be helpful to consider that our VR system is more than the sum of its parts. Yes, a VR system is a headset, controllers, and a tracking system, but the interaction of its components in concert creates the fluidity of a single machine. For example, many headsets contain spatial anchors that coordinate with the positional tracking of their accompanied touch controllers. To have controllers active in our scene without a shared headset might cause conflicts in the messaging between Unity, VRTK, and the third-party VR SDK.

To replace the UnityXRCameraRig in our Scene Hierarchy, we first locate the SDK camera object with which we will replace it. Locate the folder for the VR integration system you installed within your Project window’s Asset hierarchy. Because I installed the Oculus Integration Package, to locate my Oculus camera object, I navigate to the Project window and select Assets ➤ Oculus ➤ VR ➤ Prefabs ➤ OVRCameraRig (Figure 6-4). All figures in this chapter pertaining to an SDK-specific camera rig will portray the Oculus rig. However, VRTK supports many different brands of headsets.
../images/488645_1_En_6_Chapter/488645_1_En_6_Fig4_HTML.jpg
Figure 6-4

The virtual camera object specific to your head-mounted display can be found inside the SDK integration package downloadable from Unity

Drag the SDK camera object into the Scene Hierarchy (Figure 6-5).
../images/488645_1_En_6_Chapter/488645_1_En_6_Fig5_HTML.jpg
Figure 6-5

After dragging the SDK camera object into the Scene Hierarchy, you can delete the UnityXRCameraRig object

With the SDK camera object selected in the Scene Hierarchy, turn your attention to the Inspector window. If you are using a 6DoF headset, which offers the ability to move around a play area, set the tracking origin of the camera object in its Manager component to Floor Level (Figure 6-6). Otherwise, if you are using a 3DoF headset, which offers the ability to look around but not move through a play area, select Eye Level.
../images/488645_1_En_6_Chapter/488645_1_En_6_Fig6_HTML.jpg
Figure 6-6

The Oculus camera rig game object’s Manager component. The camera rig for your VR system might appear differently in the Inspector

Step 4: Connect the SDK Camera Rig with the TrackedAlias Game Object

Now that we have a camera rig object connected to our SDK in our Unity scene, it’s time to wrap it in our TrackedAlias prefab so that VRTK can coordinate the messaging between Unity and our third-party SDK. To do this, first click Add Component on the SDK CameraRig object in the Inspector and search for the Linked Alias Association Collection component.

With the Linked Alias Association Collection component attached to our SDK CameraRig prefab (Figure 6-7), we have permission to connect it with our TrackedAlias prefab. However, we first must declare the relationship between the elements of our SDK CameraRig prefab and our TrackedAlias prefab. We accomplish this by defining the settings in the SDK CameraRig prefab’s new Linked Alias Association component.
../images/488645_1_En_6_Chapter/488645_1_En_6_Fig7_HTML.jpg
Figure 6-7

The Oculus camera rig game object with VRTK’s Linked Alias Association Collection component attached

To define the settings in the SDK CameraRig prefab’s Linked Alias component, we drag and drop the objects of our camera rig in the Scene Hierarchy into their matching object fields in the Inspector. First, let’s define the PlayArea Settings on our Linked Alias Association Collection component by dragging the SDK CameraRig parent object, which includes its children by default, to the PlayArea Settings object field in the Inspector (Figure 6-8).
../images/488645_1_En_6_Chapter/488645_1_En_6_Fig8_HTML.jpg
Figure 6-8

Drag and drop the SDK CameraRig parent object to the PlayArea object field of the Linked Alias Association Collection script component

Next, we’ll define the headset and controller settings for the Linked Alias Association Collection component. Whereas the Headset property refers to the game object representing our physical headset, Headset Camera refers to the virtual camera within our headset that will translate our scene into VR. For our purposes, it is sufficient to drag and drop the SDK CameraRig’s CenterEyeAnchor child object into both fields (Figure 6-9).
../images/488645_1_En_6_Chapter/488645_1_En_6_Fig9_HTML.jpg
Figure 6-9

For the Oculus Rift SDK, drag and drop the CenterEyeAnchor to the Headset settings of the Linked Alias Association Collection

Similarly, we will drag and drop the LeftHandAnchor and RightHandAnchor child objects from our Scene Hierarchy into the Left Controller and Right Controller object fields in the Linked Alias Association Collection (Figure 6-10). As of this writing, VRTK does not contain velocity tracker information for certain SDK headsets and controllers. You can find more information on the VRTK web site if you are interested in exploring the feature in greater depth. For this exercise, we will leave the velocity tracker fields of the Linked Alias Association Collection component empty.
../images/488645_1_En_6_Chapter/488645_1_En_6_Fig10_HTML.jpg
Figure 6-10

To connect external controllers to the VRTK input mapping system, drag and drop left and right anchors to the Left and Right Controller Settings fields, respectively, of the Linked Alias Association Collection script attached as a component to the SDK CameraRig

With the properties of our SDK CameraRig prefab defined in the Linked Alias Association Collection component, we are finally able to connect our headset and controllers to the VRTK TrackedAlias prefab. To do so, select the TrackedAlias prefab in the Scene Hierarchy to open it in the Inspector. If you are using the same project from our previous exercise, you’ll notice that we have one camera rig in our Tracked Alias Settings Elements list, and that camera is the UnityXRCameraRig (Figure 6-11).
../images/488645_1_En_6_Chapter/488645_1_En_6_Fig11_HTML.jpg
Figure 6-11

Before adding the SDK CameraRig to the TrackedAlias Façade, there could be either zero or one camera rig listed as an element

Because we will use our SDK’s CameraRig object, we can replace the UnityXRCameraRig prefab in the Element 0 field with the SDK CameraRig prefab we set up in our Scene Hierarchy. If there are no camera rigs in the Elements list of your TrackedAlias prefab, then change the size of the Elements property by entering 1 and pressing Enter. Drag and drop the SDK CameraRig prefab from the Hierarchy into the Element 0 object field (Figure 6-12). This completes the connection between our headset’s virtual camera and VRTK’s TrackedAlias game object.
../images/488645_1_En_6_Chapter/488645_1_En_6_Fig12_HTML.jpg
Figure 6-12

After attaching the Linked Alias Association Collection script to the SDK CameraRig game object, we can drag and drop the SDK CameraRig into the Elements array of the Tracked Alias Facade

Step 5: Play-Test

Press Play on your scene. If your VR HMD and tracking are set and connected properly through Unity then you will see at least one gray rectangle tracking the movement of your left and right controllers (Figure 6-13). We will address changing the default shape of these virtual controllers in a future exercise. For now, pat yourself on the back for incorporating user movement via not only a head-mounted display but also two (or one if you’re using a 3DoF system like the Oculus Go, which only uses one controller) touch controllers.
../images/488645_1_En_6_Chapter/488645_1_En_6_Fig13_HTML.jpg
Figure 6-13

After connecting a headset and touch controllers to the VRTK TrackedAlias game object, we see the VRTK Interactor prefabs track the motion of external VR controllers in play mode

As of now, our controllers move within our virtual scene, but they don’t really do anything. Because interaction is the soul of an immersive experience, let’s turn our attention to adding a couple Unity Button Actions to our scene. First, we’ll update our CalculateInterest() function to include a Unity Button Action connected to our spacebar. Second, we’ll do the same for a button on one of our touch controllers.

Step 6: Tweak Some Code

Let’s begin by making some small changes to our Calculator script. Double-click the Calculator script in your Project window to open it in Visual Studio. Comment out the Start() and Update() functions, leaving only the public void CalculateInterest() function operable (Figure 6-14).
../images/488645_1_En_6_Chapter/488645_1_En_6_Fig14_HTML.jpg
Figure 6-14

In Visual Studio 2017, commented out code appears in green

No Comment

In Visual Studio, highlighting a block of code and pressing Ctrl+K, Ctrl+C comments code out. Ctrl+K, Ctrl+U comments code back in.

Save the Calculator script in Visual Studio and return to Unity. Allow the changes you made to your Calculator script to compile in Unity. After a few seconds, everything should be updated.

Because we moved the calling of our CalculateInterest() function from our update function, our script will not listen for our user input every frame. How will our program know when to execute our action if we removed any code that tells Unity to increase the size of our cake at the touch of a button? To the rescue, again, comes VRTK and its Unity Button Action component.

Step 7: Add a Unity Action Component

Let’s create a new empty game object in our Scene Hierarchy and call it KeyboardManager. On this object we will attach a Unity Button Action component connected to the cake object the size of which we’d like to inflate. Select the KeyboardManager game object in the hierarchy. In the Inspector, click Add Component.

The component we’d like to add is the Unity Button Action component, so search for it in the Search field (Figure 6-15). Once you’ve attached the Unity Button Action component to the KeyboardManager object, you will see the script in the Inspector. Expand the Unity Button Action script component on the KeyboardManager to see its properties (Figure 6-16).
../images/488645_1_En_6_Chapter/488645_1_En_6_Fig15_HTML.jpg
Figure 6-15

A Unity Button Action component is a VRTK script that can be attached to a game object in the Unity Inspector

../images/488645_1_En_6_Chapter/488645_1_En_6_Fig16_HTML.jpg
Figure 6-16

A Unity Button Action script has four events that can trigger an action

A Unity Button Action component has four events we can hook into.
  • Activation State Changed notifies a subscriber that an event has gone from either on to off or off to on.

  • Activated notifies a subscriber that an event has been turned on.

  • Value Changed notifies a subscriber if the true/false property of an event has changed.

  • Deactivated notifies a subscriber that an event has been turned off.

For this exercise we’re going to focus on the Activated (Boolean) event.

Step 8: Tell Our Button Component What to Do in Case of an Event

To tell our program what to do when the user sends an event to our KeyboardManager by pressing the spacebar, we have to give it a function to fire when the event occurs. What’s the function we want to tie to this event? If you guessed the action we want to fire is our CalculateInterest() function , then you are correct. Recall that we must attach scripts as components to game objects for them to operate in our scene. In the previous chapter we created a CalculatorController to hold our Calculator script. In this chapter, however, because we are going to task VRTK’s TrackedAlias object with coordinating our inputs, we are going to instead attach our Calculator script to the object whose size we want to calculate—our 3D cake.

Drag and drop the Calculator script we updated at the start of this section on to the cake object in our scene. We still have to specify what the target “cube” game object will be in our script. We want it to be the cake, so let’s drag and drop the cake object from the Hierarchy onto the Cube property of its own Calculator script. If you find this confusing, you can think of the cake, by assigning itself as its Cube property, saying, “I don’t need a CalculatorController to grow, I can call my own function myself!” Okay, cake, if you say so, but how are you going to know when to call your own grow function? Here, our adolescent cake is a bit stumped. Let’s help it out.

Select the KeyboardManager in the Hierarchy and in the Inspector click the + sign beneath the Activated (Boolean) event. An empty object field appears along with a drop-down menu that says No Function. Drag and drop the cake object into the empty object field (Figure 6-17). From the drop-down menu, select Calculator ➤ CalculateInterest(). At the bottom of the KeyboardManager’s Unity Button Action component, locate the property labeled Key Code. From the drop-down menu, select Space.
../images/488645_1_En_6_Chapter/488645_1_En_6_Fig17_HTML.jpg
Figure 6-17

Drag and drop the game object to which the desired subscriber action is attached into the object field of the Unity Button Action component

We’ve just connected our spacebar to the CalculateInterest() function located in a script on our cake game object. In Chapter 5 we accomplished this by creating a function in our Calculator script’s Update() method that used the Unity Input Manager’s GetKeyDown method.

“Okay, big deal,” you might be saying. “We still had to write some code. I don't get how using this VRTK interface made anything easier.” Well, you’d be right. Creating a Unity Button Action still required us to create our CalculateInterest() function and attach it to our cake game object (the object whose size we aim to increase by pressing the spacebar). What if we wanted to connect another button to our CalculateInterest() function? On the one hand, we could write a new function in our Update() function that calls GetKeyDown on our right touch controller instead of our keyboard. We’d also have to do the same thing if we wanted to connect our function to a button on our left touch controller. Just like that, we’ve gone from writing one function to writing three. On the other hand, we can use the VRTK TrackedAlias game object to connect different inputs to a function we only have to write once.

Creating Proxy Actions and Chaining Actions

In VRTK, this is called creating proxy actions and chaining actions. To see how it works, we’re going to connect our CalculateInterest() function to the A button on the Oculus touch controller.

Step 1: Connect Our Touch Controller Hardware to Their Virtual Counterparts

To accomplish this, we first need to bring in a couple references to our touch controller into our scene. Yes, we brought in Interactor prefabs in the previous exercise, but these simply applied shapes to our controllers in VR space. The VRTK interactor prefabs can’t communicate with the buttons, triggers, or joysticks on our controllers. For that, VRTK offers us more specific options. Navigate to the InputMappings folder within the VRTK folder in the Project window. Select Assets ➤ VRTK ➤ Prefabs ➤ CameraRig ➤ UnityXRCameraRig ➤ InputMappings (Figure 6-18).
../images/488645_1_En_6_Chapter/488645_1_En_6_Fig18_HTML.jpg
Figure 6-18

Included in VRTK are prefabs that map to Oculus and OpenVR controllers

Inside the InputMappings folder there are game objects coinciding with the VR system you’ve set up in your application. Because I have both Oculus and OpenVR set up on my project, I have four game objects in my InputMappings folder: two for the left and right Oculus controllers and two for the left and right OpenVR controllers. Select the controllers that apply to your application. Because I am developing for the Oculus Rift, I will choose the UnityXR.Oculus.LeftController game object and the UnityXR.Oculus.RightController game object. Drag the game object controllers best suited to your project into the Scene Hierarchy (Figure 6-19).
../images/488645_1_En_6_Chapter/488645_1_En_6_Fig19_HTML.jpg
Figure 6-19

Drag and drop the VRTK controller prefabs that match your VR hardware and SDK

Step 2: Map a Unity Button Action Component to Our Controller

Because I want to connect the CalculateInterest() function to the A button on my Oculus Rift touch controller, I check the Unity XR Input documentation, where I learn Unity identifies the Oculus Rift A button as Button.One, which has a Unity Button ID of 0 (Figure 6-20).
../images/488645_1_En_6_Chapter/488645_1_En_6_Fig20_HTML.jpg
Figure 6-20

In Unity, the Oculus Rift touch controller’s A button has the hardware feature name Button.One. The Unity Button ID given to Oculus Rift’s Button.One is 0. Find more at https://docs.unity3d.com/Manual/xr_input.html

Do the same for whatever input you’d like to connect the CalculateInterest() function to. For my project, I expand the child objects beneath the UnityXR.Oculus.RightController prefab in my Hierarchy. I expand ButtonOne and find two leaves: Touch[10] and Press[0] (Figure 6-21).
../images/488645_1_En_6_Chapter/488645_1_En_6_Fig21_HTML.jpg
Figure 6-21

Expanding the VRTK controller prefab in the Hierarchy reveals child objects mapped to each input

The UnityXR controller prefab should come with a Unity Button Action component already attached (Figure 6-22). If it doesn’t, add it yourself as you did earlier in this exercise with the KeyboardManager (Add Component ➤ Unity Button Action).
../images/488645_1_En_6_Chapter/488645_1_En_6_Fig22_HTML.jpg
Figure 6-22

The VRTK Input Mapping prefab game objects come with a Unity Button Action component already attached

Step 3: Define the Action to Occur in Response to a Button Event

Because we are chaining two proxy events to the same action, let’s do exactly as we did with our KeyboardManager game object (Figure 6-16). With Press[0] (or whatever XR object maps to the button of your choice on your VR system) selected, click the + sign beneath the Activated (Boolean) event on the XR controller’s Unity Button Action component.

Drag the cake object, which has the Calculator script component attached to it, from the Scene Hierarchy onto the empty object field of the Unity Button Action component. Select the Calculator ➤ CalculateInterest() function from the Function drop-down menu. For Key Code, leave the default setting, which should map to the XR button to which the Unity Button Action script is attached (Figure 6-23).
../images/488645_1_En_6_Chapter/488645_1_En_6_Fig23_HTML.jpg
Figure 6-23

VRTK sets the Key Code parameter automatically on the Unity Button Action components of input mapping prefabs

Step 4: Play-Test

Alright! We now have two unique events wired up to the same action! On your cake game object, be sure to set the Interest Rate modifier on the Calculator script component to a value like 1.06, otherwise, with the modifier set to 0, the cake will disappear after one press of a button. Then, save the scene. When you press Play and enter your VR scene, you will be able to increase the size of the cake by pressing either the spacebar or the button you specified on your VR controller. Give it a test!

Before we hand over our project to Kavya to use with her third graders, there’s just one more thing I’d like us to do to organize our project. Right now, we have two events calling the same action, but it’s not very easy to discern which events correspond to which action. Sure, you and I might know what buttons do what in our Scene Hierarchy, but if we had partners on this project, they might be left confused about the changes we’ve made to the scene since we added the TrackedAlias VRTK object. Let’s make things a bit clearer for both ourselves and everyone else by creating a game object that houses all the components involved with our CalculateInterest() function .

Step 5: Cleanup

Create an empty game object in the Scene Hierarchy and name it CalculatorManager. This object will hold all our calculator logic so it is easy to locate should we have to refactor (edit, rearrange) our code. In the Inspector, add a Boolean Action component to the CalculatorManager (Figure 6-24).
../images/488645_1_En_6_Chapter/488645_1_En_6_Fig24_HTML.jpg
Figure 6-24

Add a Boolean Action component to the CalculatorManager game object

Like the four events attached to the Unity Button Action we listed earlier, the Boolean Action component also contains an expandable property called Sources. Expand Sources on the CalculatorManager’s Boolean Action component. By default, the Size parameter of the Sources property is set to 0. Change that to 2 and press Enter (Figure 6-25).
../images/488645_1_En_6_Chapter/488645_1_En_6_Fig25_HTML.jpg
Figure 6-25

Change the size of the Sources array on the Boolean Action script component to 2

Two new fields appear: Element 0 and Element 1. We know that the two “sources” for our action in this project are key presses of both the spacebar and the touch controller’s main button. Let’s add those to the CalculatorManager’s Sources property by dragging and dropping, first, the child button object to which we attached an Activation function on our UnityXR controller prefab in the Hierarchy. Second, let’s drag and drop the KeyboardManager game object from the Hierarchy into CalculatorManager’s Element 1 parameter beneath its Sources on its Boolean Action component (Figure 6-26).
../images/488645_1_En_6_Chapter/488645_1_En_6_Fig26_HTML.jpg
Figure 6-26

Chain the two events defined in our scene to the same action by dropping them into the Sources parameters on the CalculatorManager

Now that we know what two events call our action on our Boolean Action component, let’s tell our CalculatorManager what function to call when either of our two event sources fire. Just like we did with the Unity Button Action component on game objects previously, click + under Activated (Boolean) on CalculatorManager’s Boolean Action component. Drag the cake object (with the Calculator script attached as a component) from the Hierarchy into the empty object field of the ActivatedBoolean event handler. Select the Calculator ➤ CalculateInterest() function from the drop-down menu (Figure 6-27).
../images/488645_1_En_6_Chapter/488645_1_En_6_Fig27_HTML.jpg
Figure 6-27

Drop the game object containing the desired subscriber action as a script component into the game object field of the Boolean Action component on the CalculatorManager

We now have our two input events (proxy actions) wired to the same action (chained action) on a single game object in our scene. Delete the functions listed below the Activated (Boolean) events on the Unity Button Action scripts of both the UnityXR controller button object and the KeyboardManager by clicking the - sign next to the + sign you used to add the functions (Figure 6-28). Do not delete the event you just added to the CalculatorManager’s Boolean Action component. After you remove the two event publishers on the controller button and the KeyboardManager, the CalculatorManager will be the only event publisher we have to fire off events to its subscriber, the cake object.
../images/488645_1_En_6_Chapter/488645_1_En_6_Fig28_HTML.jpg
Figure 6-28

Delete an action connected to an event handler by clicking the - icon

When you’ve confirmed that the CalculatorManager’s Boolean Action component is the only Activated event publishing to the cake object, save your scene and play-test it by pressing both the spacebar and the controller button to inflate the dimensions of the cake. If everything is in working order, recall that you can manipulate the rate at which the cake expands by changing the Interest Rate property on the Calculator script we’ve stored on our cake object in the Hierarchy.

Play Doesn’t Save

It’s important to note that changes made to your scene in play mode are not saved. If you’d like to change the Interest Rate property of the Calculator script, it’s best to stop the scene from playing, change the value, save the scene, and restart it.

That’s that! We’ve passed the Cake Calculator off to Kavya, who said her students enjoyed it and have all committed to leaving their allowance untouched in a savings account until they are 65 years old. See, VR changes lives!

Summary

Interaction is the main ingredient of an immersive VR scene. Enabling a user to affect the environment around them in VR heightens an experience. It also puts more creative power in the hands of the developers. Passive experiences become active as users move from the position of viewers to actors, to players, to characters. The further we move along through this book, the closer we will come to connecting a user’s consciousness with a reality that is virtual. Involving their eyes and hands are early steps toward capturing their hearts and minds.

In this chapter you replaced a UnityXRCameraRig with an SDK-specific camera rig. You also connected physical controllers to their virtual counterparts. Using the VRTK TrackedAlias object, you connected a user’s controllers to a scripted event. Using VRTK Button components, you mapped this event to inputs from two different sources—a keyboard and a controller—creating proxy actions. By creating a single game manager object with a VRTK Boolean Action component, you chained these two actions to one event without writing any new code.

Although powerful and convenient, the buttons on a VR controller are only some of the input options available to users of VR. Many controllers include triggers and joysticks in addition to buttons. In this chapter we focused on boolean events that delivered on/off signals, but in the next chapter we will learn about creating Axis Actions for the triggers and joysticks on our VR controllers. Because they convey more complex data than boolean actions, trigger events allow us, as developers, to put even more power to influence the immersive environment into the hands of the user.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.172.252