Tracking Gaze for each floor

  1. Create a folder called Scripts inside the Assets folder.
  2. Add a new script by navigating from the context menu Create | C# Scripts, name it FloorInteractionManager.
  3. Open the script file in Visual Studio.

By default, the FloorInteractionManager class is inherited from MonoBehaviour. MonoBehaviour is the base class from which every Unity script derives. In the next step, implement IFocusable interface in the FloorInteractionManager class. This interface implements the methods OnFocusEnter() and OnFocusExit(), which invoke when Gaze Enter and Gaze Exit, respectively. So, the default skeleton for the FloorInteractionManager class would be as follows:

public class FloorInteractionManager : MonoBehaviour, IFocusable {
public void OnFocusEnter()
{
}

public void OnFocusExit()
{
}

// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}

At this point in time, we don't want to change anything in the base skeleton. Just to check whether everything is tagged and working fine or not, add only a line inside the OnFocusEnter() method that returns the tag name of the Gazed object eventually that will be our floor number:

public void OnFocusEnter()
{
var floorNo = this.gameObject.tag;
}

Attach the FloorInteractionManager script with all the floor glass objects where we have added the Box Collider. Once done, if you inspect any of the floors in the Inspector window, they will have the following components:

Floor Game Object attached with script

While Transform, Mesh Renderer, and Mesh Filter come with a base 3D Model, we have added the Box Collider and script as components as a part of the development.

That's it!

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

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