So i am using object pooling to spawn enemies, but once defeated I need them to clear the data from their script.
the code below is how I tried to do it, the first 4 things are nessicary,
but I the other 3 need to be cleared. I made them public to work here, but I would rather have them private.
void SpawnEnemy ()
{
GameObject enemy = transform.GetChild(0).gameObject;
if (enemy != null)
{
enemy.transform.position = transform.position;
enemy.GetComponent<EnemyScript>().path = path;
enemy.GetComponent<EnemyScript>().healthbar = healthbar;
enemy.GetComponent<EnemyScript>().health = enemyPrefab.GetComponent<EnemyScript>().health;
enemy.GetComponent<EnemyScript>().gateScript = gateScript;
enemy.GetComponent<EnemyScript>().nextPoint = enemyPrefab.GetComponent<EnemyScript>().nextPoint;
enemy.GetComponent<EnemyScript>().existTime = enemyPrefab.GetComponent<EnemyScript>().existTime;
enemy.GetComponent<EnemyScript>().startTime = enemyPrefab.GetComponent<EnemyScript>().startTime;
enemy.SetActive(true);
enemy.transform.SetSiblingIndex(enemiesToPool - 1);
}
}
Also, the last 3 need to be 0 when spawned, otherwise the enemies go crazy