SHARE
TWEET

HotspotAudioCueV1 / Anthony / NextRealityNews HowTos

AnthonyC Apr 17th, 2017 (edited) 138 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top