I’m doing a beginner unity course. I’m trying to add a powerup that when collided with will increase the players shooting speed. I’m using a coroutine to apply a waitforseconds to return back to the normal shooting speed. I can’t seem to work out what I’m doing wrong. Any help is much appreciated
Thank you, that’s removed the error. However the powerup seems to only increase my fire rate after I stop my game and won’t increase during the gameplay
[[quote=“brigas, post:4, topic: 791009, username:brigas”]
can you show your player script
[/quote]
This is the player script https://pastebin.com/62ptthr4
As a workaround you can also deactivate the collider and all the power up renderes on Pickup() and then destroy when the corutine ends. Anyways, take in mind how to manage many pickups coexisting at the same time. Should they restart the timer? Should remainingTime + newTime get added? And so on
This is now working But after I pickup a second powerup I get the error
"Coroutine couldn’t be started because the the game object ‘Player’ is inactive!
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
Player:AdjustFirePeriod(Single, Single) (at Assets/Scripts/Player.cs:68)
Powerup:pickup(Collider2D) (at Assets/Scripts/Powerup.cs:28)
Powerup:OnTriggerEnter2D(Collider2D) (at Assets/Scripts/Powerup.cs:23)
" What does it mean by inactive? Edit
Just noticed it works fine when I add my instanced player gameobject to my powerup, but the problem is with adding my prefab player to the powerup. Edit 2
I’m stupid and didn’t realise my instanced powerup in the scene was a different prefab to the one dropped by my enemies lol. Got there in the end! Thank you so much for the help