Just found this works fine within Unity, but crashes on the phone upon startup, without an error message! :?
First I define a public array to hold some sound effects:
public AudioSource[ ] SFX_MowMow_Thrown_Short,
SFX_MowMow_Thrown_Med,
SFX_MowMow_Thrown_Long;
the sound files for these are then filled in through the editor.
Then I set up my arrays:
AudioSource[ ][ ][ ] aSFX_Throw = new AudioSource[2][ ][ ];
AudioSource[ ][ ] MowMowThrows = new AudioSource[3][ ];
…and fill one in:
MowMowThrows[0] = SFX_MowMow_Thrown_Short;
MowMowThrows[1] = SFX_MowMow_Thrown_Med;
MowMowThrows[2] = SFX_MowMow_Thrown_Long;
aSFX_Throw[0] = MowMowThrows;
Then, as an example of playing one, I use:
aSFX_Throw[0][2][Random.Range( 0, aSFX_Throw[0][2].Length-1 )].Play( );
Is anyone aware of any array-related bugs? Again, it works fine when running from within Unity, but on the phone it crashes. If I comment out the above code, everything works fine.
I can code around the problem, but thought I’d better point it out - obscure it may be
I’m using such a construct for my onscreen keyboard so no array related issue.
Sure that the sound you try to playback converts over to iphone at all? Ie is it a wav that you set to compress within Unity?
The sound is played after a certain action, so it’s not had chance to be played before the crash occurs.
In your code, are you using [ ] [ ] [ ], or [,] ?
Thanks
I’m using [ ][ ] as you are (needed, there are 3 lines of keys with different lengths) for the sound.
what I would recommend is that you debug it a bit.
Take the value and assign it and then play the sound from that variable after you ensured its not 0
from the source given it would be null actually and therefor just crash.
also you fill the [ ][ ] array but for playback you use the [ ][ ][ ] array which is not the same.
Perhaps its just [ ][ ][ ] that can not be used, iPhone is .NET 1.1 to keep in mind.
Found it. It’s 3 dimensions it doesn’t like :
AudioSource[][][] aSFX_Throw = new AudioSource[2][][];
I found a handy thing called ArrayList, so I now have :
ArrayList MowMowThrows = new ArrayList( );
ArrayList aSFX_Throw = new ArrayList( );
...
MowMowThrows.Add( SFX_MowMow_Thrown_Short );
MowMowThrows.Add( SFX_MowMow_Thrown_Med );
MowMowThrows.Add( SFX_MowMow_Thrown_Long );
aSFX_Throw.Add( MowMowThrows );
...
ArrayList sndBank = (ArrayList)aSFX_Throw[0];
AudioSource[] sndDist = (AudioSource[])sndBank[2];
sndDist[Random.Range( 0, sndDist.Length-1 )].Play( );
It’s a bit long-winded, but it works!