KeyCode.Wを押してから徐々にAudioSource.volumeを3fまで上げて行きたいのですが
現状のコードではフリーズしてしまいます。
どのようにすればよいでしょうか?
using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerManager : MonoBehaviour { private AudioSource audioSource; private float volumeWhile = 3f; void Start() { audioSource = GetComponent<AudioSource>(); } // Update is called once per frame void Update() { if (Input.GetKey(KeyCode.W)) { if (!audioSource.isPlaying) { while (audioSource.volume < volumeWhile) { audioSource.Play(); audioSource.volume += 0.5f; if (audioSource.volume == volumeWhile) break; } } } if (Input.GetKeyUp(KeyCode.W)) { audioSource.Stop(); } } }

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。