好了,所以我把这段代码缩小到一行:
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/