My problem is, I have some enemies. I they all have a script with a transform array in it. When I spawn in, I want to add my own transform to the enemies enemy array!
Code:
ENEMY SCRIPT:
public Transform[] Enemies;
SPAWN IN SCRIPT:
public GameObject Player; //Assign in unity
void Start(){
Instantiate(Player);
//Add transform to Enemies[] which is in ENEMY SCRIPT
}
Use a generic list instead, its better for this application
public class Player : MonoBehaviour {
public GameObject Player;
public EnemyScript enemyScript;
void Start(){
GameObject clone = (GameObject)Instantiate(Player);
enmeyScript.enemyList.Add(clone.Transform)
}
}
public class EnemyScript : MonoBehaviour {
public List<Transform> enemyList = new List<Transform();
}