Hi all, I'm trying to build a 2.5D platformer however I could seem to get the scene transition to work with a fade. My script for the empty object with a collider is as follows: Code (CSharp): using UnityEngine; using System.Collections; using UnityEngine.SceneManagement; using UnityEngine.UI; public class JumpScene1 : MonoBehaviour { public Image black; public Animator animate; public void OnTriggerEnter(Collider c) { if (c.CompareTag("Player")) { StartCoroutine(Fading()); } } IEnumerator Fading() { animate.SetBool("Fade", true); yield return new WaitUntil(() => black.color.a == 1); SceneManager.LoadScene("Scene_2_Test"); } } Please help. Thanks.
Hello, though green is a different colour.. there is a better way to post code on the forums! Please read this and edit your post https://forum.unity.com/threads/using-code-tags-properly.143875/ What's working / not? Does the trigger happen, the animate fade? etc..
Thanks for the advice, I've edited my post. The problem I encounter is that the Fading Coroutine doesn't trigger at all. If I were to only run the SceneManager code in the tag, the scene transition works fine but of course without the fade animation. I'm very sure the fade animation works as it also triggers at the start of my scene. Hope this is enough information. Thanks.
Not sure what to say. Just to double check, are you saying the full coroutine doesn't finish or it doesn't even start? And, do you notice the colour alpha value changing at all?
I suppose it doesn't start as the scene transition doesn't occurs when the player collides into the collider space. It just passes right through it.
Well, if it's just a trigger, you can pass right through it, that's normal. You didn't answer about the image's alpha value changing at all? You can do a Debug.Log (or print) statement at the top of the coroutine to see if it started at all.. (and in your trigger, too, to double check?). Try to go step by step through things, check them , and see where it's failing..
Sorry for the late reply. As I've also added the same fade animation to the beginning of the level, I can see the alpha value changed here. However, it doesn't occur in the trigger. I've added in the Debug,Log as you suggested: Code (CSharp): using UnityEngine; using System.Collections; using UnityEngine.SceneManagement; using UnityEngine.UI; public class JumpScene1 : MonoBehaviour { public Image black; public Animator animate; public void OnTriggerEnter(Collider c) { Debug.Log("Collision Detected"); if (c.CompareTag("Player")) { Debug.Log("Coroutine Started"); StartCoroutine(Fading()); //SceneManager.LoadScene("Scene_2_Test"); } } IEnumerator Fading() { animate.SetBool("Fade", true); yield return new WaitUntil(() => black.color.a == 1); SceneManager.LoadScene("Scene_2_Test"); } } It seems that both the trigger and the coroutine have be activated but neither the fade nor the scene change occurred.
Hm, not sure what to say. Something is wrong with the animation, or the object is deactivated maybe ?
I finally found a way to make the fade transition work with a few tweaks to the script: Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; public class AnimationOnTrigger : MonoBehaviour { public string scene; public Color loadColor = Color.black; public void OnTriggerEnter(Collider c) { if (c.CompareTag("Player")) { Initiate.Fade(scene, loadColor, 0.5f); } } } I'm posting this here for anyone who may encounter the same problem in the future.