< Summary

Class:PlayQuickSound
Assembly:Test
File(s):E:/Unity/Unity Project/VR-Room/Assets/_Course Library/Scripts/Test/PlayQuickSound.cs
Covered lines:19
Uncovered lines:0
Coverable lines:19
Total lines:42
Line coverage:100% (19 of 19)
Covered branches:0
Total branches:0
Covered methods:4
Total methods:4
Method coverage:100% (4 of 4)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
PlayQuickSound()0%000100%
Awake()0%000100%
Play()0%000100%
OnValidate()0%000100%

File(s)

E:/Unity/Unity Project/VR-Room/Assets/_Course Library/Scripts/Test/PlayQuickSound.cs

#LineLine coverage
 1using UnityEngine;
 2
 3/// <summary>
 4/// Play a simple sounds using Play one shot with volume, and pitch
 5/// </summary>
 6[RequireComponent(typeof(AudioSource))]
 7public class PlayQuickSound : MonoBehaviour
 8{
 9    [Tooltip("The sound that is played")]
 1210    public AudioClip sound = null;
 11
 12    [Tooltip("The volume of the sound")]
 1213    public float volume = 1.0f;
 14
 15    [Tooltip("The range of pitch the sound is played at (-pitch, pitch)")]
 1216    [Range(0, 1)] public float randomPitchVariance = 0.0f;
 17
 1218    private AudioSource audioSource = null;
 19
 1220    private float defaultPitch = 1.0f;
 21
 22    private void Awake()
 623    {
 624        audioSource = GetComponent<AudioSource>();
 625    }
 26
 27    public void Play()
 828    {
 829        float randomVariance = Random.Range(-randomPitchVariance, randomPitchVariance);
 830        randomVariance += defaultPitch;
 31
 832        audioSource.pitch = randomVariance;
 833        audioSource.PlayOneShot(sound, volume);
 834        audioSource.pitch = defaultPitch;
 835    }
 36
 37    private void OnValidate()
 1238    {
 1239        AudioSource audioSource = GetComponent<AudioSource>();
 1240        audioSource.playOnAwake = false;
 1241    }
 42}