UnityのAddressableを使って音声リソースを参照して音を出すまではできました。
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.AddressableAssets; using UnityEngine.ResourceManagement.AsyncOperations; using UnityEngine.UI; public class TestScript : MonoBehaviour { #pragma warning disable 649 [SerializeField]GameObject SoundsObject; [SerializeField]GameObject ImageObject; AudioSource testAudioSource; AudioClip audioClip; // Start is called before the first frame update void Start() { AddressableScript(); } void AddressableScript() { Addressables.LoadAssetAsync<AudioClip>("Assets/Sounds/epinpon.ogg").Completed += op => { SoundsObject.GetComponent<AudioSource>().PlayOneShot(op.Result as AudioClip); }; } }
次にこのaudioClipの時間を取得するためにaudioClip.lengthを取得したく
SoundsObject.GetComponent<AudioSource>().PlayOneShot(op.Result as AudioClip);を
下記に変更しました。
void AddressableScript() { Addressables.LoadAssetAsync<AudioClip>("Assets/Sounds/epinpon.ogg").Completed += op => { audioClip = op.Result as audioClip; SoundsObject.GetComponent<AudioSource>().PlayOneShot(audioClip); int audioClipNum = audioClip.length; }; }
にしたところ下記のエラーが出ます。どこがいけないのでしょうか?
error CS0246: The type or namespace name 'audioClip' could not be found (are you missing a using directive or an assembly reference?)
環境)
PC: mac
Unity2018.3.0f2
言語:C#

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