< 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")]
 4710    public AudioClip sound = null;
 11
 12    [Tooltip("The volume of the sound")]
 4713    public float volume = 1.0f;
 14
 15    [Tooltip("The range of pitch the sound is played at (-pitch, pitch)")]
 4716    [Range(0, 1)] public float randomPitchVariance = 0.0f;
 17
 4718    private AudioSource audioSource = null;
 19
 4720    private float defaultPitch = 1.0f;
 21
 22    private void Awake()
 2023    {
 2024        audioSource = GetComponent<AudioSource>();
 2025    }
 26
 27    public void Play()
 10228    {
 10229        float randomVariance = Random.Range(-randomPitchVariance, randomPitchVariance);
 10230        randomVariance += defaultPitch;
 31
 10232        audioSource.pitch = randomVariance;
 10233        audioSource.PlayOneShot(sound, volume);
 10234        audioSource.pitch = defaultPitch;
 10235    }
 36
 37    private void OnValidate()
 6738    {
 6739        AudioSource audioSource = GetComponent<AudioSource>();
 6740        audioSource.playOnAwake = false;
 6741    }
 42}