Tanoda
SliderVolume.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9using UnityEngine;
10using UnityEngine.UI;
11using System.Collections;
12
13namespace Leap.Unity.InputModule {
14 public class SliderVolume : MonoBehaviour {
15 public AudioSource source;
16 float volume = 0f;
17 float currentValue = -1f;
18 float previousValue = -1f;
19 float maxValue = 0f;
20 float TimeLastSlid = 0f;
21
22 void Start() {
23 maxValue = GetComponent<Slider>().maxValue;
24 }
25
26 void Update() {
27 volume = Mathf.Lerp(volume, Mathf.Abs(currentValue - previousValue) * 40f, 0.4f);
28 previousValue = currentValue;
29 source.volume = volume;
30
31 if (Time.time - TimeLastSlid > 0.5f) {
32 source.Stop();
33 } else if (!source.isPlaying) {
34 source.Play();
35 }
36 }
37
38 public void setSliderSoundVolume(float sliderposition) {
39 currentValue = sliderposition / maxValue;
40 TimeLastSlid = Time.time;
41 }
42 }
43}
void setSliderSoundVolume(float sliderposition)
Definition: SliderVolume.cs:38