audio と animator の速度値を制御するsliderを
ボタンを押すことで slider の値を一気に0にすることで
audioとanimatorの速度値を0にするスクリプトを書きたいです。
using
1using System.Collections.Generic; 2using UnityEngine; 3using UnityEngine.UI; 4using UnityEngine.Audio; 5 6public class SpeedScript : MonoBehaviour { 7 8 public GameObject Dancer1; 9 public GameObject Dancer2; 10 Animator anim1; 11 Animator anim2; 12 Slider slider; 13 float slidervalue; 14 AudioSource audios; 15 public AudioMixer audiomix; 16 17 // Use this for initialization 18 void Start () { 19 slider = GetComponent<Slider>(); 20 slider.value = 0; 21 slidervalue = slider.value; 22 anim1 = Dancer1.GetComponent<Animator>(); 23 anim2 = Dancer2.GetComponent<Animator>(); 24 audios = Dancer1.GetComponent<AudioSource>(); 25 } 26 27 // Update is called once per frame 28 void Update () { 29 if (slider.value != slidervalue) 30 { 31 slidervalue = slider.value; 32 } 33 anim1.speed = slider.value / 10; 34 anim2.speed = slider.value / 10; 35 audios.pitch = slider.value / 10; 36 audiomix.SetFloat("Pitch Param", 10 / slider.value); 37 if (slider.value == 11) 38 { 39 40 anim1.speed = 2; 41 anim2.speed = 2; 42 audios.pitch = 2; 43 audiomix.SetFloat("Pitch Param", 0.5f); 44 } 45 46 } 47} 48
こちらのコードはaudioとanimatorの速度値を制御するsliderのスクリプトで
実際にうまく動いています。ですが下記に示すボタンのスクリプトはアタッチして実行しても何も反応しませんでした。slider.value = 0にしてもなぜ変化が起きないのでしょうか。どのように修正すればよいのでしょうか。
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class SuspendScript : MonoBehaviour { public Slider speedslider; // Use this for initialization void Start () { speedslider = GetComponent<Slider>(); } // Update is called once per frame void Update () { } public void Suspend() { speedslider.value = 0; } }
回答1件
あなたの回答
tips
プレビュー