Question about coroutine

Hi, I have a question regarding the activation of the coroutine created in this lecture.

The coroutine is activated in the Start() method of the Tower.cs script. But when is the Start() method called/activated? Is it when the OnMouseDown() method in the Tile.cs script calls the CreateTower() method in Tower.cs? Or does it activate when the tower is instantiated?

Does the coroutine start even if the player doesn’t have enough gold and CreateTower() method returns false?

Thank you.

Hi,

The Start method gets executed after the game object was created/spawned/instantiated and after the Awake method (if there is one) was called.

Since we don’t have any restriction in our code in regards to starting the coroutine, the coroutine will always start.

If no tower got instantiated because we didn’t have enough gold, the Start method of the non-existing Tower object will not get executed.

Did this make sense? :slight_smile:


See also:

Hi Nina,

Thanks for your answer! Yes, it makes perfect sense! :slight_smile:

I also have a little off-topic question: Will there be a Unity 2020.1 version course of the Zombie Runner game as well? If so, do you have any estimate when it might happen? I’m about to start with the old version, but if the new version is coming out soon, I might wait a bit :slight_smile:

Thanks!

Since Rick remastered the ZR game not long ago, there currently are no plans to update it again. Just start with the current ZR version (not with the superold one ;)).

Alright, thanks a lot :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms