I have code that instantiates characters, but it instantiates them multiple times at one spot. So, I want to know a way to only make them instantiate only once.
Any help would be appreciated. Thanks.
void Generate()
{
if(cooldown==0)
{
for(int j = 0; j < targets.Length;j++)
{
for(int i = 0; i < apartments.Length; i++)
{
j = Random.Range(0,targets.Length);
i = Random.Range(0,apartments.Length);
if(!targets[j]||!apartments[i])
return;
if(!instantiated){
Instantiate(targets[j],apartments[i].transform.position, Quaternion.identity);
instantiated = true;
cooldown = timeInterval;
}
}
}
}
else
{
instantiated = false;
}
}