- Home /
Unity Fade in Unity 6.4 UI, animations...etc
I would like to make a unity fade in , so that when my game starts the game fades in, and i can have this maybe as a scene?, so i can have it before each of my scenes. Would i need to use the animation feature to change the alpha of a black panel. I dont know but if anyone has any ideas, then please share :D, Thanks
Answer by Mmmpies · Feb 05, 2015 at 08:26 PM
Sure, If a static panel is OK you can put a canvas add a panel and put a CavasGroup on the base canvas.
You can fade from 0 Alpha to 1 Alpha by changing the CanvasGroup value.
using UnityEngine.UI; // add this at the top
public CanvasGroup myCanvasGroup;
private bool fadeIn;
void Start()
{
fadeIn =true;
myCanvasGroup.alpha = 0f;
}
void Update()
{
if(fadeIn)
{
myCanvasGroup.alpha = myCanvasGroup.alpha + Time.deltaTime;
if(myCanvasGroup.alpha >= 1)
{
myCanvasGroup.alpha = 1;
fadeIn = false;
}
}
}
Thank you, the code works but it fades out, which i wanted aswell, but what values would i change to make in fade in? Thanks
And how would i have it so it comes on at specific times ?
No problem, Start at 1 and do
myCanvasGroup.alpha = myCanvasGroup.alpha - Time.deltaTime;
if(myCanvasGroup.alpha <= 0)
{
myCanvasGroup.alpha = 0;
fadeIn = false;
}
Also if you wanted it to take 2 seconds the divide Time.deltaTime by how many seconds you want so
myCanvasGroup.alpha = myCanvasGroup.alpha - (Time.deltaTime / 2.4f);
that example is 2.4 second.
You should also untick the interactable and blocksraycast if only using for image effects.
and to do at any time have both a fadeIn bool and a fadeOut bool, make them public and just set them when you want a menu to either fade in or out.
You'll need both the fadeIn and fadeOut sections in Update for that to work but you should have enough code to get it working.
I tried the code, but it made the alpha go up, because i ran the program and the alpha started at 1, which was correct, but it just keep rising? Sorry for all the questions
Wait, no im a idiot I forgot to add the $$anonymous$$us, so i sorted it thank you so much :D
Your answer
Follow this Question
Related Questions
save my ragdolls current pose in c# 1 Answer
Make object gradually fade from left to right,Make object gradually disappear from left to right. 0 Answers
Multiple Cars not working 1 Answer
Unity crashes when trying to fadein and fadeout sound 1 Answer
How can I fade in/out an object nonstop automatic ? 2 Answers