I have a basic scene switch code someone helped me with.
using UnityEngine;
using System.Collections;
public class SceneSwitch02 : MonoBehaviour {
public float waitTime = 30f;
// Use this for initialization
void Start () {
StartCoroutine(SwitchSceneTime());
}
private IEnumerator SwitchSceneTime() {
yield return new WaitForSeconds (waitTime);
Application.LoadLevel (1);
}
}
The code works perfectly fine. The scene does switch…however when the scene switches, it freezes for like 4 seconds before going to scene 2. So someone advised me I have a black fade when it switches scenes. But I have no clue as to how I would do that.
I have sort of gathered that I need to use some sort of black image, but thats all I know. So I have a GameObject, and added a ‘black’ image texture, so in the ‘game’ view it covers the whole screen/camera view.
I looked up lots of videos and threads and still cant understand it. They are either really confusing and, having tried to disect the code to understand what it is, I dont 100% fully get it. Or, nearly all of the examples/videos use some sort of collider object in the scene and in the code. Whereas for me, there is only a camera in my scene that the player looks around before the scene switches after 30 seconds.
All I want is a simple code that, after 30 seconds a black image fades in (so essentially its covering the frozen scene), and then fades out to reveal scene 2. As its viewed in the GearVR, what the player sees when the scene freezes, is a snapshot of the scenes camera angle, and around it, its black.
Hopefully this information helps so I can fade switching more, cheers
hmm. Well if I am gonna be honest I dont really understand it haha. I get that you have linked me different parts, and I need to somehow use my knowledge of scripting (which I have none btw), and put it together to create some code for it to all work.
I am talking to someone through messages who is helping me with it atm, hes kindly given, just fixing a few issues though
But I appreciate your help, and going out to find the videos which is kind of you
The way we handle fades in some of our apps is with a tween system. We use LeanTween, but dotween is suppose to be good also. Both have free versions. You just create a UI image, set it’s color to whatever you want, then expand it to fill the screen. Set alpha to 0 and then use the tween to fade the image in. Simple and effective.
Ah yes, someone on here reccomended me that. I wanted to have a ‘thanks for watching’ fade in, at the end of my scene which they helped me with. Although, for this situation, I am not sure how it will work as I presume I will need code?
So once the 1st scene starts, in 25 seconds fade in black overlay image (have it black when it switches scenes so the player does not see it frozen), and fade out when scene 2 is loaded. I will have a look at it though and see
You can simply have an fade image in both scenes. Scene 1, fade image has 0 alpha. Scene 2, fade image has max alpha. Then you just fade in on scene 1 and fade out on scene 2. Both tween engines have different ways of doing this with a simple call.
So I just use the same ‘fade image’ for scene 1 and scene 2. When you say a ‘simple call’ do you mean some sort of code? Is there a link where I can just use the code?
Someone kindly gave me this code, that I used for an image fading in at the end of the scene. I am not sure how I could change it to work with scene switching though
using UnityEngine;
using DG.Tweening; // this is DOTween
public class Fader : MonoBehaviour
{
// duration from the start of the scene until this fade begins.
public float delayBeforeFadingIn;
// duration of fade
public float fadeDurationSeconds;
// type of easing to use for the fade
public Ease fadeEase = Ease.Linear;
CanvasGroup canvasGroup;
private void Awake()
{
canvasGroup = GetComponent<CanvasGroup>();
// start the canvas invisible
canvasGroup.alpha = 0;
}
private void Start()
{
canvasGroup.DOFade(1, fadeDurationSeconds).SetDelay(delayBeforeFadingIn).SetEase(fadeEase);
}
}
I don’t use dotTween, so it’s a guess based on what I see.
They are doing something with fading in a canvas group.
I’m assuming you could replace canvasGroup with an image as it’s target. and the 1 is what you are fading to. So 1 is fade in. If that were 0 it would fade out.
Image fadeImage;
//Fade in
fadeImage.DOFade(1, fadeDurationSeconds).SetDelay(delayBeforeFadingIn).SetEase(fadeEase);
//Fade out
fadeImage.DOFade(0, fadeDurationSeconds).SetDelay(delayBeforeFadingIn).SetEase(fadeEase);
Just a guess. There was someone on these forums that used dotween and could probably shed more insight.