Beispiel #1
0
 /// <summary>
 /// When the View loads, play a sound if appropriate
 /// </summary>
 protected override void OnViewLoaded()
 {
     // There might not be a sound, or it might be null
     SoundMapping.TryGetValue(this.Icon, out var sound);
     if (sound != null)
     {
         sound.Play();
     }
 }
Beispiel #2
0
    // Randomly choose a sound from a set of audio clips and slightly
    // adjust their pitch
    private void RandomizeSfx(bool isRandomPitch, SoundMapping mapping)
    {
        // Generate a random number between 0 and the length of the
        // array of clips passed in
        int randomIndex = Random.Range(0, mapping.AudioClips.Length);

        // Choose a random pitch to play the clip at
        float pitch = isRandomPitch ?
                      Random.Range(LOWEST_PITCH, HIGHEST_PITCH) : 1;

        // Set the pitch of the audio source to the randomly chosen pitch
        mapping.AudioSource.pitch = pitch;

        // Play the clip
        mapping.AudioSource.clip = mapping.AudioClips[randomIndex];
        mapping.AudioSource.Play();
    }