Quantcast
Channel: Questions in topic: "dontdestroyonload"
Viewing all articles
Browse latest Browse all 416

Dont Destory OnLoad for music background did not play after change Audio Clip

$
0
0
using UnityEngine; using System.Collections; public class SoundManager : MonoBehaviour { public static SoundManager control; AudioSource audioSource; public AudioClip[] audio; public bool isPlaying; void Awake() { if(control==null) { DontDestroyOnLoad (gameObject); control=this; } else if(control !=this) { Destroy(gameObject); } } void Start() { audioSource = GetComponent (); } void Update() { if (Application.loadedLevel == 0 || Application.loadedLevel == 1) { ChangeSound (); } else if (Application.loadedLevel == 3) { if(!isPlaying) { audioSource.clip = audio [1]; audioSource.Play(); isPlaying=true; print("playing"); } } } void ChangeSound() { isPlaying=false; audioSource.clip = audio [0]; } } Any error or logic that i miss? I check that it print "playing" but no sound is playing . Edit * done * if forget to check one time playing , it loop the playing function , that why is no sound is playing

Viewing all articles
Browse latest Browse all 416

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>