Hey everyone,
One of the reason I really like Unity, as opposed to other game engines, is the community and vast wealth of information and resources made available to it. In that respect, I thought I’d take the time to highlight some such tips, that in my view simply do not get enough exposure.
All my tips involve tools that are free or freely accessible, and so I really encourage you to have a go at them and thus expand your game dev arsenal and knowledge.
Subject this week: DOTween. You can get it free from the asset store
DOTween is a Brackeys top 5 Unity editor[1] - one he calls feeling dumb for not using it earlier - and is used to make simple animations.
To showcase it how much it would simplify your life, I’ll use the Fader class from the RPG course
RPG course
public IEnumerator FadeOut(float time)
{
while(canvasGroup.alpha < 1)
{
canvasGroup.alpha += Time.DeltaTime / time;
yield return null;
}
}
public IEnumerator FadeIn(float time)
{
while(canvasGroup.alpha > 0)
{
canvasGroup.alpha -= Time.DeltaTime / time;
yield return null;
}
}
and now with DOTween, this is how it would look like:
public void FadeOut(float time) { canvasGroup.DOFade(0, time); }
public void FadeIn(float time) { canvasGroup.DOFade(1, time); }
As you can see, with DOTween you are given extra methods to use out of the box - called extension methods - and all you need to do is just call these methods… in this case, the DOFade() method on the CanvasGroup. It doesn’t even need to be a co-routine as DOTween will manage it for you (making sure the fading happens across the desired number of frames)
Now, the keener of you may have the following question: “but the RPG course version does other things before and after the fading, like loading a new scene during the whole co-routine between the fades…”. Well that wouldn’t be a problem thanks to DOTween sequences, but this post is long enough and I’ll cover that as a future Tips Tuesday post!
Hope you found this useful and interesting…