If player attacks my object, its ‘Struck’ method will push it in some direction.
Coroutine ‘RecentlyStruck’ is assigned to struckCorutine variable, coroutine keeps track of recentlyStruck bool which I need for other methods.
If another player attacks this object while struckCoroutine is not null, current coroutine will be stopped and replaced with new one. (Resseting timer)
Here’s my question: Is this clean way of doing this?
I am doing projects for my github so I want this to be efficient and not complicated for no reason.
(Its simple example, I am using similar technique of ‘refreshing’ for more advanced stuff)
For this one I will switch to using timer, but as I said, I have different couroutines that are much more advanced and I need to have a way to ‘refresh’ them.
I posted this one to explain my problem easier (less wall of text).
The way you’re doing it is correct, but unless you’re doing something else with the coroutine variable, you don’t need to explicitly set it to null – you can just reassign it to the new coroutine. This is the pattern I use in my code: