I make an simple AR concert, I have a reset button and when the user click it the singer will dissappear (GameObject.setActive(false)). However, when I clicked the play button again, the audio source not giving any sound. How I handle it ? I’ve initialized in my Start() function.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class MikuController : MonoBehaviour {
public GameObject self;
public Button resetButton;
private AudioSource musicAudio;
private Vector3 startPos;
// Use this for initialization
void Start () {
startPos = transform.position;
musicAudio = GetComponent<AudioSource> ();
musicAudio.Play ();
resetButton.onClick.AddListener (reset);
}
// Update is called once per frame
void Update () {
}
void reset() {
/* stop all music */
musicAudio.Stop ();
/* set gameobject to inactive */
self.SetActive (false);
}
}