Example #1
0
    public void FadeOut(float speed)
    {
        fadeSpeed = speed;
        VolFadeValue = 1.0f;

        SoundState = SoundStates.FadingOut;
    }
Example #2
0
    public void FadeIn(float speed, bool loop)
    {
        transform.GetComponent<AudioSource>().loop = loop;

        fadeSpeed = speed;
        VolFadeValue = 0.0f;
        transform.GetComponent<AudioSource>().Play();

        SoundState = SoundStates.FadingIn;
    }
Example #3
0
    public void Update()
    {
        if(SoundLoopCounter > 0 && !transform.GetComponent<AudioSource>().isPlaying)
        {
         			transform.GetComponent<AudioSource>().Play();
            SoundLoopCounter--;
        }

        if(SoundState == SoundStates.FadingIn)
        {
            VolFadeValue += Mathf.Clamp01(Time.deltaTime / fadeSpeed);

            transform.GetComponent<AudioSource>().volume = VolFadeValue;

            if(VolFadeValue >= 1.0f)
                SoundState = SoundStates.None;
        }
        else if(SoundState == SoundStates.FadingOut)
        {
            VolFadeValue -= Mathf.Clamp01(Time.deltaTime / fadeSpeed);

            transform.GetComponent<AudioSource>().volume = VolFadeValue;

            if(VolFadeValue <= 0.0f)
                SoundState = SoundStates.None;
        }
    }
Example #4
0
 public void Awake()
 {
     SoundLoopCounter = 0;
     SoundState = SoundStates.None;
 }