hi, so what i want to do is access game script (EnemyScript) that are attached to an instantiated game object. I have attached the script to the original game object,
This is the the script (EnemyManager) to spawn the enemy game object and also get the script component from instantiated game object
public class EnemyManager : MonoBehaviour
{
public GameObject zombear;
public GameObject temp;
public GameObject[] activeEnemy = new GameObject[10];//Maximum 10 enemy exist in the game
public int count;
private void Start()
{
count = 0;
}
private void Update()
{
if(TheManager.instance.GetGameStateManager().CurrentPhase == GameStateManager.GamePhase.EnemyPhase)
{
if (activeEnemy[0] != null)
{
for (int i = 0; i < count; i++)
{
if(activeEnemy[count].GetComponent<EnemyScript>())
activeEnemy[count].GetComponent<EnemyScript>().EnemyAction();
else
TheManager.instance.GetCanvasManagerStatus().logUpdate("Script not detected");
}
}
else
TheManager.instance.GetCanvasManagerStatus().logUpdate("No enemy");
}
}
public void spawnZombear(Transform coordinates)
{
temp = Instantiate(zombear, new Vector3(coordinates.position.x, 0.1f, coordinates.position.z), Quaternion.identity);
activeEnemy[count] = temp;
count++;
}
}
i’ve debug it and it got the error on the activeEnemy[count].GetComponent()
what is wrong??