- Home /
2D Platformer (Unity 4.3) - How are the AudioClip arrays initialized?
Looking at, for example, PlayerHealth.cs, I see the following three lines which reference the ouchClips AudioClip array:
public AudioClip[] ouchClips;
...
// Play a random clip of the player getting hurt.
int i = Random.Range (0, ouchClips.Length);
AudioSource.PlayClipAtPoint(ouchClips[i], transform.position)
I cannot for the life of me see where the "ouch" audio clips—Player-ouch(1..4)—are assigned to this array. I see no other code mentioning the array, nor have I been able to find anything in the Inspector. It just seems to work magically.
If anyone could demystify this for me, I'd be very appreciative!
Answer by JeffreyD · Feb 26, 2014 at 01:37 AM
Hi, know very little about the 2D setup but looking at the scripts I'm guessing that the clips are loaded into the array in the inspector since the array is a public var. So, in the inspector looking at the script component PlayerHealth.cs, set the array size to 4 (since I found 4 clips in the audio/Player/Ouch directory.). Then drop the clips into the clips locations create by setting the Ouch array size.
I tried uploading an image but it does not appear to be working. Hope this makes sense without looking at an image.
Your answer
![](https://koobas.hobune.stream/wayback/20220613134739im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Player color change on collision -1 Answers
How To Create 2D Arrays 1 Answer
Staring a 2D game 2 Answers
Change gravity on button 1 Answer