The Theft Protection

Myths and Facts About Identity Theft


Hi guys. Welcome back to my unity3d tutorial series: Puzzle Game In the last part, i complete “Checkpoint” concept. You can see i play here my character comes back to checkpoint when he hits deathpoint In this part, i’m going to create Scene Changing concept with “scene fading” Ok, open scenes folder and create a new scene and name it by “Lobby” to make scene changing from Lobby to Main, i need a script So, open scripts folder and create a new script with name “LobbyCtl” Wait util unity complete creating script and opening it i don’t need Update method, so, delete it now. create a new method to handle scene changing in this method, i use SceneManager LoadSceneAsync to load scene and determine if the operation has completed remember to import UnityEngine.SceneManagerment Ok, LoadSceneAsync Because i need loading Main scene, so, pass Main string here next, wait ulti the “async” completes loading to use these things, change from void to IEnumerator when scene is loaded, set it active use SceneManager.GetSceneByName to get scene that i loaded before for more convinent, i pass sceneName string to this method Change these to sceneName ok, it seem be fine to call this method, use StartCoroutine pass method name and scene name which i need to load ok, try a test open Lobby scene craete an empty game object to attach LobbyCtl script rename it reset it’s transform and drag script to it i need to setup something Open File, BuildSetting, then add Lobby and Main to Scene In Build drag themes to here. Remeber that Lobby is first close this window and try a test ok, Main scene is loaded but it’s quite fast Because in the Start method of LobbyCtl, i call loadScene method imediately You can see here now. i’ll create scene fading trasition Create a new Ui, Image setup somethings fore canvas. I set it as HD screen stretch the image to full sceen change the view to 2d to focus the image, select it and hit F change color to black ok, it’s fine rename it for more convinient now, i need craeting animator controller and animation for SceneFader double click on aniamtor file to open it then, add animation to this animator controller by dragging it here right click and create a new Empty state. Because the animation does not run at the beginning make it as default state then make a trasition from it to fading transition state at parameters tab, create a new trigger name it by “fade” select this arrow to add condition ok, comeback to Scene tab i’m going to add Animator component to this Image and drag the controller to it select the object and open Animation window by hitting Ctrl 6 resize the window to editing easier make a record now at the beginning, i set the image transparent to 0 i think fading transition will take 1.5s to complete so, set transparent to 255 here let’s see how it works it seem be fine i think 1s is better let’s write some code here, i need adding the fading transition here declare a public Animator variable before loading the scene, i need start fading So, set trigger and pass “fade” string that named before when the stuffs complete, do the fadeOut before doing it, i need wait the transition complete here coppy and paste here do the fadeOut here the string is changed, so i need change it on animator tab to mkae fadeOut animation, just dupplicate fadeIn and set speed to -1 make a transition to it, then add condition rename it to fadeIn and create a new Trigger: fadeOut now, add condition here let’s check again now, drag Image object here to attach animator i’ll make a button. When i click on that button, the fading starts and Main scene will be loaded after that So, craete a method for button to call it Move this line here now, let’s create a button Do some stuffs to make it look better now, add OnClick Event for the button Because the fade image should not be visible at the beginning. So, set it invisible here And remember make it active before do the fading ok, it’s time to test Click the button to change to Main sceen It’s seem qutie fast let’s check the code the fadeOut is not shown because Lobby Scene is destroyed when changing to Main scene So, i need load scene in Additive mode Test again to see what happens Remember to set canvas order to a big number. This thing keep the fade image at the top of the game view ok, the fadeOut is shown. But the light of Main scene is quite bright. Why? Because there is a light here in the Lobby Scene. I don’t need it for my Lobby scene. So exit play mode and delete it The Lobby scene do not need skybox too, so, i set clear flag to solid color Pick any color, such as gray color I reorder the button and fade image. This make the button visible when the fadeIn shows Declare that button here. Because i want to hide it when the fadeOut completes write the code here try a test now remember to attach the button to LobbyCtl rename the button for more convinent ok, let’s see what happens It’s seem ok but something wrong with the fading Open animator tab. Drag and dock it here to check a animation replay and check it i need to change something. Delete old transitions and recreate it the transitions start from AnyState is better add the condition like i did before ok, let’s check again the transition is ok, but the Main scene is actived quite soon so, comeback to the code and change wait time amount here, because the transition takes 1s to complete. So, i’ll wait 1.1f second now, it’s seem ok. Let’s test again Perfect. Everything is fine let’s test one time again to enjoy it you can also see the animation running at the animator tab ok, i’ve just done a simple scene changer with fading effect. Hope you like it! See you later Thanks for watching. If this video is useful with you, please leave a like and comment. You can see more by clicking one of these here

1 thought on “Unity 3d Tutorial – Puzzle Game [Part 7] – Change Scene Or Level With Fading Transition

Leave comment

Your email address will not be published. Required fields are marked with *.