Changing the color
So, the final lesson in this chapter will add interaction to change the color of our material. Instead of Gaze and Gesture though, we will use a voice command:
- With
LeftRect
selected, click on theAdd Component
button. - Scroll down and click on the
New Script
option. - Type
ChangeRectColor
in thenew script
dialog; then, click onCreate
and thenAdd
.
Just like last time, instead of creating a second script for the right side, we will add the same script to RightRect
using the following steps:
- Select
RightRect
. - Click on the
Add Component
button. - Click on
Scripts
. - Select
ChangeRectColor
from the list.
This script will be slightly more complex than the previous one. From a scripting standpoint, materials are handled by the Renderer class. So, we get a reference to the renderer that is attached to this object. Then, we create a couple of bools.
We will use the OnFocusEvent.cs
HTK class attached to an object and with two functions in our ChangeRectColor script, we can change the color of...