Hearing works similarly to vision but doesn't take into account the nodes direct visibility because of the properties of the sound. However, we still need a sound receiver in order to make it work. Instead of making an agent a direct sound receiver, in this recipe, the sound travels along the sound graph and is perceived by the graph nodes.
It is important to have grasped the chapter regarding path finding in order to understand the inner workings of the graph-based recipes.
Create the emitter class:
using UnityEngine; using System.Collections; using System.Collections.Generic; public class EmitterGraph : MonoBehaviour { // next steps }
Declare the member variables:
public int soundIntensity; public Graph soundGraph; public GameObject emitterObj;
Implement the validation of the emitter object's reference:
public void Start() { if (emitterObj == null) emitterObj = gameObject; }