[HELP!]CoRoutine cannot get started because GameObject is InActive

I’m currently working on the Laser defender game and adding PowerUps.
Some background info:
In the enemy_behaviour script whenever enemy shoots I created a randomally Instatiator of the powerUp general prefab and it’s sprite onto the scene. In the player controller I check the name of the sprite and by that I can decide which powerUp was taken.
At first my whole code of the powerUps was in the player controller script and it actually worked great but was too messy. Now that I had split it into methods in the class of the PowerUp it is not working.
I’m adding the scripts of PowerUp class and player controller class.

I’ve added methods in the PowerUp class and called them from the player controller but I get errors.

First I tried to implement only the Quick powerUp.

Whenever I pick up the PowerUp of quick and it tries to start a Coroutine for the quick player(in the “CallQuicky” function in the PowerUp script)This error pops up: (I have added the Player prefab to the PowerUp script)


It drives me crazy because it worked when it was messy but in the same script - but now with the split in the scripts this error happens.

If you could take a look at the new scripts please and the previous ones maybe and explain why this is happening because nothing has changed really…

Here’s the old script of player controller script: Old player controller
Here’s the new player controller script: New player controller
Here’s the new Power up script: Power Up script

Thank you so much

Hi Ori,

I did looked at your code but this is very difficult to debug without the whole project. The only thing I can think is if we look at the error message is when you instantiate your prefab try to use gameObject.setActive(true) before starting the coroutine.

Please read this post on how I could help you.

Privacy & Terms