Is there a way to only run the script when the game object is spawned within the game itself.
For example. i have these two scripts, the Start and the Spawn.
I want everything within the Start script to run only when the Spawn class spawns out the enemy.
Sorry for again. Er.
in my Starts Class script i have this function
function Start()
{
getStart = GameObject.FindWithTag("Start");
getArray = getStart.GetComponent(StageWaypoint).carrotArray;
}
in my spawn class, i have the
function Update() {
for (var x = 0; x < carrotNo ; x ++)
{
var pos = Vector3( ((x + randPos) ) , 0.3, 0) * spacing ;
//Debug.Log(spacing + " spacing");
if(x < 5)
{
CarrotIn1 = Instantiate(carrotPrefab1, pos, Quaternion.identity);
CarrotIn1.renderer.material.mainTexture = texture1;
carrotArray.Push(CarrotIn1);
}
else if( x > 4)
{
pos = Vector3 ((x + (randPos + randDiff) ), 0.3, 0)* spacing;
CarrotIn2 = Instantiate(carrotPrefab2, pos, Quaternion.identity);
CarrotIn2.renderer.material.mainTexture = texture2;
carrotArray.Push(CarrotIn1);
}
}
}
however my method is that when i run the Start function in the Starts script, getArray = nothing as the carrot have not been spawned yet. Therefore, is there a way whereby, i could only run the
getArray = getStart.GetComponent(StageWaypoint).carrotArray;
after that carrot have been spawned and placed into the array
thanks alot. =D
Sorry for asking this dumb question. =/