This is my audio manager script(singleton)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AudioManager : MonoBehaviour {
private static AudioManager _instance;
public static AudioManager Instance {
get {
if (_instance == null) {
Debug.Log ("No AudioManager gameobject was found");
}
return _instance;
}
}
void Awake(){
_instance = this;
}
void Start(){
}
public AudioSource AddAudio(GameObject targetGameObject, AudioClip clip, bool loop, bool playOnAwake, float volume){
AudioSource newAudio = targetGameObject.AddComponent<AudioSource> ();
newAudio.clip = clip;
newAudio.loop = loop;
newAudio.playOnAwake = playOnAwake;
newAudio.volume = volume;
return newAudio;
}
}
and this is my Shoot script(attached to enemy and player object) that calls the singleton
void Awake(){
shootAudio = AudioManager.Instance.AddAudio (this.gameObject, shootClip, loop, playOnAwake, audioVolume);
}
void ShootStuff(){
shootAudio.Play();
}
I set up up this way so that if the ShootScript(or any other script) requires another sound clip to be played, i can just create a new audio source in the script, reference it to the instance of AudioManager’s AddAudio function, and a AudioSource component will be created automatically.
The problem arises when i clone the Enemy prefab, the ShootScriptComponent on the cloned Enemy automatically disables when i run the game. Why is it that the Player object that has the same shootScript attached works fine but not for the cloned Enemy, and how should i fix it??? Thanks