Hi,
I have spawners in my game that, well, spawn enemy and for pooling and recycling them, I need to pass reference of the spawner to the enemies it spawns so prior to their death, they would use that reference to access the spawner and tell it that they are ready to get recycled.
So how can I have that reference in the newly created objects?
Thanks.
Assign Instantiate to a reference variable, then get the script and assign the spawner to it. Supposing that the enemy script is EnemyScript.js and that it has a GameObject variable named spawner, you could do the following (spawner script):
public var enemyPrefab: GameObject; // this is the enemy prefab reference
function CreateEnemy(pos: Vector3, rot: Quaternion){
var enemy: GameObject = Instantiate(enemyPrefab, pos, rot);
enemy.GetComponent(EnemyScript).spawner = gameObject;
}