Hi everyone,
I have a problem about instantiated object’s instance reference.
I have 2 script which names are EnemyController.cs and EnemyAttack.cs.
I am instantiating objects every x seconds and calling method from EnemyAttack.cs with instance reference in EnemyController.cs
Red object instantiated with my code. Error says the yellow object is not active even though I instantiated the red object.
Error is:
Coroutine couldn’t be started because the the game object ‘Zombie_0(Clone)’ is inactive!
UnityEngine.MonoBehaviour:StartCoroutine (System.Collections.IEnumerator)
Sample code here:
EnemyController.cs
public class EnemyController : MonoBehaviour
{
private EnemyAttack enemyAttack;
private void Start()
{
enemyAttack = EnemyAttack.instance;
}
private void StateExecute()
{
enemyAttack.Attack(); // not working
// GetComponent<EnemyAttack>().Attack(); --> this works.
}
}
EnemyAttack.cs
public class EnemyAttack : MonoBehaviour
{
public static EnemyAttack instance;
private void Awake()
{
instance = this;
}
public void Attack()
{
// do some works
StartCoroutine(AttackRoutine());
}
}