Hello everyone
I have 2 script and im trying that the dontdestroyonload doesnt duplicate the objects when i come back to the first scene i tried to count the tag of the object and if its zero the it should instantiate a prefab but i didnt work
here are my scripts
The duplicate solver:
#pragma strict
var audio2 : GameObject;
var clonedObject : Transform;
var audioCounter : int;
function Update ()
{
audioCounter = GameObject.FindGameObjectsWithTag("audio");
if(audioCounter == 1)
{
Instantiate(audio2, clonedObject.transform.position, transform.rotation);
}
}
and the script with the dontdestroyonload
#pragma strict
function Start () {
}
function Update ()
{
DontDestroyOnLoad(this);
if(Application.loadedLevel <= 1)
{
audio.volume = MenuMastering.myVolume;
}
if(Application.loadedLevel == 2)
{
audio.volume = 0;
}
}
if anyone can tell me how i can make the gameobject with the second script not to be duplictaed it would be very apreciatet and if someone posts a singleton pattern link or script please let it be in java i dont know c#.
thanks in advance skullbeats1
↧