- Home /
This question was
closed May 18, 2014 at 06:02 AM by
Loius for the following reason:
Duplicate Question
Can't start Coroutine since object is "Inactive"
Here's the guilty coroutine in EnemyAnim.cs
IEnumerator LeftRightMovement()
{
while (true)
{
for (int i = 0; i < 100; i++)
{
Debug.Log("executing");
transform.position = new Vector2(transform.position.x + y, transform.position.y);
yield return new WaitForSeconds(0.02f);
}
new WaitForSeconds(3f);
AssignMoveLeftRight(transform.position); //stops current coroutine without yield break and start a new instance of this one
}
}
I'm trying to start it from another script called EnemySpawner.cs this way :
public class EnemySpawner : MonoBehaviour {
public Vector3 ThisPos;
public GameObject Enemy;
EnemyAnim enemyAnim;
void Start () {
ThisPos = transform.position;
enemyAnim = Enemy.GetComponent<EnemyAnim>();
Enemy.transform.position = ThisPos;
Instantiate(Enemy);
}
void Update () {
if (Input.GetKeyDown(KeyCode.R))
{ Instantiate(Enemy); enemyAnim.AssignMoveLeftRight(transform.position); } //Enemy.GetComponent<EnemyAnim>().AssignMoveLeftRight(transform.position); }
}
Inside the AssignMoveLeftRight(vector3 vector) method there's the line that asks to start the coroutine, the method resides in EnemyAnim.cs
Log error sais "Coroutine couldn't be started because the the game object 'Attack' is inactive!"
Comment
Answer by rgowen · May 18, 2014 at 02:39 AM
This has already been answered here:
http://answers.unity3d.com/questions/452857/coroutine-couldnt-be-started-because-the-the-game.html
This is not an answer and the solutions you provided in that link doesn't apply to my case