Posts

Showing posts from November, 2017

Fade in and fade out Script for Unity 3d

Image
A Fader?: Is your game looking for a bit of polish? Having a simple fade transition from scenes or transition from a point in a game can make all the difference. The outcome: The Method: This uses a Coroutine to fade in/out over a specified time and using a specified amount of 'steps' for a smooth transition. This method takes a Unity UI image and adjusts the alpha until it is 0 or 100%. /// <summary> /// This is used when a Unity UI image is needed to fade /// </summary> /// <param name="image"></param> /// <param name="fadeIn"></param> /// <param name="fadeTimeSec"></param> /// <returns></returns> IEnumerator Fader(Image image, bool fadeIn, float fadeTimeSec) { // the alpha of the image cannot be set on its own so a new color needs to be created Color tempColor = image.color; // The amount when additioned or subtracti