- Home /
Question by
sidonk · Apr 04, 2015 at 08:38 PM ·
audiosource
unity crashing when audiosource plays on load
been looking all over the net but cant find a answer to this. when I start the game with audiosource muted there is no problem, but when the audiosource is not muted it crashes unity and i need to restart the program by force closing it. I think its my soundcheck method but i dont get why cus its only checking for the playerprefs on start/awake();
Check:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Check : MonoBehaviour {
public Toggle toggle;
public string FX;
public SoundController sc;
void Start(){
sc = GameObject.Find ("SoundController").GetComponent<SoundController> ();
SoundCheck ();
}
public void SoundCheck()
{
FX = PlayerPrefs.GetString ("fx");
if (FX == "enabled") {
toggle.isOn = true;
} else if (FX == "muted"){
toggle.isOn = false;
}
}
SoundController:
using UnityEngine;
using System.Collections;
public class SoundController : MonoBehaviour {
public AudioClip ScoreIncrease;
public static SoundController Static ;
public AudioSource audioSources;
//public AudioSource scoreCount,bgSound ;
void Start () {
Static = this;
}
// Update is called once per frame
public void PlayScoreIncrease()
{
swithAudioSources (ScoreIncrease);
}
void swithAudioSources( AudioClip clip)
{
audioSources.PlayOneShot(clip);
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613192155im_/https://answers.unity.com/themes/thub/images/avi.jpg)