audio - 如何正确使用getComponants获取音频数组?

标签 audio unity3d unityscript

好了,所以我把这段代码缩小到一行:

gameObject.GetComponents(AudioSource)[0].audio.Play();

这行给我这个错误:
InvalidCastException: Cannot cast from source type to destination type.
scriptexplosion+$Start$4+$.MoveNext () (at Assets/scriptexplosion.js:7)

我的问题是如何将组件数组转换为AudioSource数组?

最佳答案

显然,您必须使用此代码使GetComponents()返回类型(在本例中为AudioSource):

gameObject.GetComponents<AudioSource>();

关于audio - 如何正确使用getComponants获取音频数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15652423/

相关文章:

android - 如何在Android上的音频播放器中添加停止功能?

ios - 如何在 iOS 中检测系统计时器关闭

iphone - 如何在uiscrollview中滑动图像时添加短声音

audio - 在 Squeak Smalltalk 中解码 WAV 文件

c++ - 非托管代码和unity3d代码之间的双向通信

unity3d - Unity3d Undo是一个EditorWindow [用于 bool 和字符串]

ios - 关闭 iOS 模式后,产生 WaitForSeconds 中断 (Unity 3D)

android - Unity android中的水平面检测

ios - libc++abi.dylib : terminating with uncaught exception of type Il2CppExceptionWrapper on restore IAP

regex - 这是正则表达式吗?