Setting up the AudioSouce

Creating an Audio Source

An audio source is a Unity component that can be attached to any Unity object. For the purpose of this guide we will just be using an empty asset.

  1. Create an empty object in the scene.
  2. Select the object and in the Inspector, click Add Component. 
     
  3. Select Audio > AudioSource.
     
  4. In the component set, Audio Clip to the WAV asset you imported.
     

Hooking Up AudioSource in Code

To play back this audio source on the GamePad, we need to configure it in a script.

  1. Add a new Script component to the game object. In this tutorial, we will name it AudioPlayer.
     
  2. Edit that script.
  3. In order to get the AudioSource playing, the code requires the following.
    1. Access to the AudioSource
    2. Audio source applied to an AudioSourceOutput
    3. AudioSource being told to play

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      using UnityEngine;
      using System.Collections;
      using WiiU = UnityEngine.WiiU;

      public class AudioPlayer : MonoBehaviour {

          private AudioSource source;

          // Use this for initialization
          void Start () {

              // Get the AudioSource from the object and assign it to the GamePad.
              source = GetComponent<AudioSource>();
              WiiU.AudioSourceOutput.Assign(source, WiiU.AudioOutput.GamePad);
              source.loop = true;
              source.Play();
          }
      }
  4. Build and run the project and your audio will play on the GamePad.

 

 


CONFIDENTIAL