< Summary

Class:PlayQuickSound
Assembly:Test
File(s):E:/Unity/Unity Project/VR-Basics/Assets/_Course Library/Scripts/Core/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-Basics/Assets/_Course Library/Scripts/Core/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")]
 2010    public AudioClip sound = null;
 11
 12    [Tooltip("The volume of the sound")]
 2013    public float volume = 1.0f;
 14
 15    [Tooltip("The range of pitch the sound is played at (-pitch, pitch)")]
 2016    [Range(0, 1)] public float randomPitchVariance = 0.0f;
 17
 2018    private AudioSource audioSource = null;
 19
 2020    private float defaultPitch = 1.0f;
 21
 22    private void Awake()
 1023    {
 1024        audioSource = GetComponent<AudioSource>();
 1025    }
 26
 27    public void Play()
 19128    {
 19129        float randomVariance = Random.Range(-randomPitchVariance, randomPitchVariance);
 19130        randomVariance += defaultPitch;
 31
 19132        audioSource.pitch = randomVariance;
 19133        audioSource.PlayOneShot(sound, volume);
 19134        audioSource.pitch = defaultPitch;
 19135    }
 36
 37    private void OnValidate()
 2038    {
 2039        AudioSource audioSource = GetComponent<AudioSource>();
 2040        audioSource.playOnAwake = false;
 2041    }
 42}