Advertisement
AnthonyC

HotspotAudioCueV1 / Anthony / NextRealityNews HowTos

Apr 17th, 2017
558
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.60 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class HotspotAudioCue : MonoBehaviour {
  4.  
  5.     public AudioClip[] clips;
  6.  
  7.     private AudioSource audioSource;
  8.  
  9.     // Use this for initialization
  10.     void Start () {
  11.         audioSource = GetComponent<AudioSource>();
  12.     }
  13.  
  14.     private void OnEnable()
  15.     {
  16.         Hotspot.OnEntered += OnHotspotEnter;
  17.     }
  18.  
  19.     private void OnDisable()
  20.     {
  21.         Hotspot.OnEntered -= OnHotspotEnter;
  22.     }
  23.  
  24.     private void OnHotspotEnter()
  25.     {
  26.         int randomNum = Random.Range(0, clips.Length);
  27.         audioSource.clip = clips[randomNum];
  28.         audioSource.Play();
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement