var enemyLv1:GameObject;
var health:int;
var maxTime:float;
var numProduce:int;
private var readyProduce:boolean;
private var slot = new Array(numProduce);
private var timer:float;
function Start()
{
timer = 0.0;
readyProduce = false;
}
function Update ()
{
if(readyProduce == true)
{
Produce();
}
else
{
timer +=Time.deltaTime;
if(timer >= maxTime)
{
readyProduce = true;
}
}
}
function OnCollisionEnter(object:Collision)
{
if(object.gameObject.tag=="pdamager" || object.gameObject.name == "3rd Person Controller")
{
Debug.Log(health);
health -=10;
Debug.Log(health);
if(object.gameObject.tag=="pdamager")
{
var currentDamager:GameObject = object.gameObject;
Destroy(currentDamager);
}
}
}
function Produce()
{
for(var i = 0;i<numProduce;i++)
{
if(slot[i+1] == null)
{
slot[i+1] = Instantiate (enemyLv1,gameObject.transform.position,gameObject.transform.rotation);
}
}
readyProduce = false;
}
this object supposed to create another gameobject called “enemyLv1” and i dont want the number of “enemyLv1” its produce become more than the number of “numProduce”
somehow this object doesnt create anyhting and i keep getting error “ArgumentOutOfRangeException: Index is less than 0 or more than or equal to the list count” on this line
if(slot[i+1] == null)
i dont know what ive done wrong with my array plsss help me ![]()
i have attached my gameobject already and assign a number for everything already…
thx :).