2013-03-27 20 views
2

好了,所以我得到這個代碼,我縮小到一個行:如何正確使用getComponants來獲取音頻數組?

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數組?

回答

0

試試這個:

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

那一個給了我這個:Assets/scriptexplosion.js(7,34):BCE0048:類型'System.Type'不支持切片。 雖然這是個好主意。 – CyanPrime 2013-03-27 05:32:09

1

顯然,你一定要使用此代碼,使GetComponents()返回類型(在這種情況下,的AudioSource):

gameObject.GetComponents<AudioSource>(); 
相關問題