Cannot Stop Instantiating The Object

Hi ,

I’m trying to instantiate my zombie object , firstly I tried to instantiate it 5 times but it doesn’t stop instantiating

#pragma strict

public var Oyuncu : Transform ;

public var Zombear : GameObject ;

public var ZombiSayisi : int;
public var ZombieXpos : int = -35 ;

public var ZombearMoveSpeed : float = 5.0f ;
public var ZombiUzakligi : float;

public var YaklastiMi : boolean = false;
public var VurulduMu : boolean = false;
public var ZombieSpawn : boolean = true;

function Start () {
    ZombiSayisi = 5;
    ZombieSpawner(ZombiSayisi);
}

function Update () {
    
    ZombiUzakligi = Vector3.Distance(transform.position,Oyuncu.transform.position);
    if(ZombiUzakligi <= 120)
    {
        YaklastiMi = true;
    }
    if(YaklastiMi || VurulduMu)
    {
        transform.LookAt(Oyuncu);
    }
    transform.Translate(Vector3.forward*Time.deltaTime*ZombearMoveSpeed);
}

function ZombieSpawner(ZombiSayisi : int)
    {
        var a : int ;
        for(a = 0 ; a < ZombiSayisi ; a++)
        {
            Instantiate(Zombear , new Vector3 (-35 , 60 ,5 ) , Quaternion.identity );
        }
    }

Start() is called once per instance of this class. If you have this class on multiple objects, it could be called multiple times. That includes the Zombear that you’re instantiating. I’d recommend checking to see if you have more than one copy of this class.

I’m not so familiar with Javascript, but I know that in C#, if you want to have multiple copies of this class, but only want the contents of Start() to happen once, then do this:

static bool started = false;

function Start()
{
    if (started) return;
    started = true;
    ZombiSayisi = 5;
    ZombieSpawner(ZombiSayisi);
}

To use that, you’d need to look up whatever the Javascript equivalent is for a static bool.