Hi there. Recenty my unity editor started crashing. It freezes kompletely and I need to use the task manager to terminate it. It happens during testing my scene at random points and more frequent when I quit testing. I dug up the log in AppData\Local\Unity\Editor but nothing related to the crash appears there.
The problem occured first after I added background audio loops and never appeared when the corresponding gameobject was deactivated (so far). The audio loops are in the it format and the preview shows: 32bit, 48000Hz, stereo, unlimited, 167,7 kb (it).
The script which manages the audio clips works as intended (see below).
I have no idea what causes those crashes. Any help is appreciated.
BackgroundMusic.js :
var clips : AudioClip[];
private var _audio : AudioSource;
function Start () {
_audio = GetComponent(AudioSource);
if(clips.Length == 0) Debug.Log("No AudioClip assigned!");
_audio.loop = true;
PickRandom();
_audio.Play();
}
function Update () {
if(Input.GetKeyDown(KeyCode.M)){
_audio.mute = !_audio.mute;
}
if(Input.GetKeyDown(KeyCode.N)){
PickNext();
}
}
function PickRandom() : void {
var rand : int = Random.Range(0, clips.length);
_audio.clip = clips[rand];
Debug.Log("currently playing " + _audio.clip.name);
_audio.Play();
}
function GetIndex() : int {
for(var j : int = 0; j < clips.length ; j++){
if(_audio.clip.name == clips[j].name){
return j + 1 ;
}
}
Debug.Log("BackgroundMusic: GetIndex() failed. return 0");
return 0;
}
function PickNext() : void {
var index = GetIndex();
if(index == clips.Length) index = 0;
_audio.clip = clips[index];
Debug.Log("currently playing " + _audio.clip.name);
_audio.Play();
}
@script RequireComponent(AudioSource)