Hi,
While I was looking for solution about fadein/out on scene I find package in assets store. With some modification it did the job.
Is it a good way to do or should I use my own scripts ?
Thanks
Hi,
While I was looking for solution about fadein/out on scene I find package in assets store. With some modification it did the job.
Is it a good way to do or should I use my own scripts ?
Thanks
I think the main objective of the task was to get you to find a way of achieving it through code, that said, if you have found an asset that does this for you, then you have gained experience using the assets
Take a look at coroutines if you haven’t already
See also;
Ok, done … at least
I finally found this tuto : http://gamedevelopertips.com/unity-how-fade-between-scenes/
And after about 2 hours of searching, reading, and understanding how the things work, I manage to change my levelmanager by the faderController
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class FadeController : MonoBehaviour {
public float fadeTimer;
public Image fadeOutUIImage;
public enum FadeDirection
{
In, //Alpha = 1
Out // Alpha = 0
}
// Use this for initialization
void Start () {
fadeOutUIImage = GetComponent<Image> ();
}
void OnEnable () {
// Fade Panel is active at begining so start fade Out
StartCoroutine(Fade(FadeDirection.Out));
}
public IEnumerator Fade(FadeDirection direction) {
// Fade depending on given Direction
// Get the good alpha value
float alpha = (direction == FadeDirection.Out)? 1 : 0;
float fadeEndValue = (direction == FadeDirection.Out)? 0 : 1;
if (direction == FadeDirection.Out) {
while (alpha >= fadeEndValue)
{
SetColorImage (ref alpha, direction);
yield return null;
}
// disable the panel
fadeOutUIImage.enabled = false;
} else {
// active before changing alpha
fadeOutUIImage.enabled = true;
while (alpha <= fadeEndValue)
{
SetColorImage (ref alpha, direction);
yield return null;
}
}
}
private void SetColorImage(ref float alpha, FadeDirection fadeDirection)
{
fadeOutUIImage.color = new Color (fadeOutUIImage.color.r,fadeOutUIImage.color.g, fadeOutUIImage.color.b, alpha);
alpha += Time.deltaTime / fadeTimer * ((fadeDirection == FadeDirection.Out)? -1 : 1) ;
}
public IEnumerator FadeAndLoadScene (string name, int nextScene) {
// On call, first Fade In, then Load new scene
yield return Fade (FadeDirection.In);
if (nextScene == -2) {
SceneManager.LoadScene (name);
} else {
SceneManager.LoadScene(nextScene);
}
}
public void LoadLevel (string name) {
StartCoroutine (FadeAndLoadScene (name, -2));
}
public void LoadNextLevel() {
StartCoroutine (FadeAndLoadScene ("", SceneManager.GetActiveScene ().buildIndex + 1));
}
}
So go on now, I have some more Lectures do follow
Hi!!
I’ve been looking over several sites trying to find a good solution where I can fade in and out over scenes.
You say that these solution worked for you, but i sitll can’t get it. On the tuto, it says that we need to add a Raw Image, but then I can’t asign it to the script. How could you manage to make it functional?
Thank you!!