im instantiating an object which is gonna play the background music for my game. On the Awake() function I check if there is a gameobject with the tag "MusicPlayer" on it, and if there isn't any I instantiate a prefab (the music player prefab with the tag "MusicPlayer" on it).
Now my issue is this :
It keeps instantiating the prefabs even if there is one or more music players(objects with the "MusicPlayer" tag on them). Why is this happening ?
Here is my code :
var musicPrefab : Transform;
function Awake()
{
if(GameObject.FindWithTag("MusicPlayer") == null)
{
Instantiate(musicPrefab,transform.position,transform.rotation);
}
}
I also have a script that makes the music player not be destroyed upon the level reload. This is the script :
function Start()
{
DontDestroyOnLoad (gameObject);
}
Thank you for your time, I hope I was clear enough.
GameManager
or directly on theMusicPlayer
? You make get some value from reading this. \$\endgroup\$