Hi,
I used DontDestroyOnLoad in my script. I have declared it on my awake function and i have put this script on one empty gameobject. Totally i have three scene, i attached this script on my first scene, when i cal the another scene i got this gameobject to that scene and again when i go back to my first scene from second scene that gameobject(wherei have put this script) is creating more like infinity.
I dont know why its happen for avoiding this i add another script for deleting that extra object. that script is here.
using UnityEngine;
using System.Collections;
public class DelectExtra : MonoBehaviour {
private GameObject[] sobjet;
private bool delete;
int i;
// Use this for initialization
void Start () {
i = 0;
delete = false;
sobjet = GameObject.FindGameObjectsWithTag("Script");
}
// Update is called once per frame
void Update () {
i = sobjet.Length;
if(sobjet.Length > 10)
delete = true;
else if(sobjet.Length < 10)
{
delete = false;
}
if(delete)
DestroyObject(sobjet[i]);
print(sobjet.Length+ " "+ delete);
}
}
this is the script i used to delete the extra objects.
please help to do this
Thanks.