/// <summary> /// Finds the IAudioInfluencer objects that are to be applied to the audio source. /// </summary> /// <returns>Collection of IAudioInfluencers between the user and the game object.</returns> private List<IAudioInfluencer> GetInfluencers() { List<IAudioInfluencer> influencers = new List<IAudioInfluencer>(); Transform cameraTransform = CameraCache.Main.transform; // Influencers take effect only when between the emitter and the user. // Perform a raycast from the user toward the object. Vector3 direction = (gameObject.transform.position - cameraTransform.position).normalized; float distance = Vector3.Distance(cameraTransform.position, gameObject.transform.position); int count = UnityPhysics.RaycastNonAlloc(cameraTransform.position, direction, hits, distance, UnityPhysics.DefaultRaycastLayers, QueryTriggerInteraction.Ignore); for (int i = 0; i < count; i++) { IAudioInfluencer influencer = hits[i].collider.gameObject.GetComponentInParent<IAudioInfluencer>(); if (influencer != null) { influencers.Add(influencer); } } return influencers; }