Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

pause before loading scene

Discussion in '2D' started by motivision, Feb 28, 2020.

  1. motivision

    motivision

    Joined:
    Dec 3, 2019
    Posts:
    28
    hi everyone

    find solution which work for me for loading scene with pause like this

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class LoadingScene : MonoBehaviour {
    6.  
    7.  
    8.   //IEnumerator Generics
    9.   IEnumerator pauseLoadingScene()
    10.     {
    11.         yield return new WaitForSeconds(5f);    
    12.     }
    13.  
    14.  
    15.  
    16.  
    17.     // Start is called before the first frame update
    18.     void Start()
    19.     {    
    20.        StartCoroutine(pauseLoadingScene());
    21.     }
    22.  
    23.  
    24.  
    25.     void Update()   {
    26.     }
    27.  
    28.  
    29.  
    30. }


    anybody know easy way, how loading scene forexample like this ?

    Code (CSharp):
    1. using System.Collections;
    2. using UnityEngine;
    3. using UnityEngine.SceneManagement;
    4.  
    5.  
    6. public class finalWall5 : MonoBehaviour {
    7.                
    8.  
    9.     public GameObject finalWallLevel5;
    10.  
    11.     //wall particle effect
    12.     public GameObject finalwall5pe;
    13.  
    14.  
    15.     private GameManagerLevels GMControl;
    16.     public string loadinglevel;
    17.          
    18.  
    19.     // Start is called before the first frame update
    20.     void Start()
    21.     {
    22.         finalwallpe.SetActive(false);
    23.         GMControl = FindObjectOfType<GameManagerLevels>();      
    24.     }
    25.                
    26.  
    27.  
    28.     public void checkscore500coll()
    29.     {
    30.  
    31.     #if UNITY_ANDROID
    32.         if (GMControl.currentScore == 500)
    33.      {  
    34.  
    35.     //snd effect
    36.     //particle effect
    37.          
    38.  
    39.     Time.timeScale = 1f;
    40.  
    41.     SceneManager.LoadScene(loadinglevel);
    42.  
    43.     }
    44.     #endif
    45.  
    46.  
    47.     }
    48.  
    49. }


    big problem for me what I can`t use snd or particle effect rightly because that`s not work for me, and scene loading

    thanks for advices
     
  2. motivision

    motivision

    Joined:
    Dec 3, 2019
    Posts:
    28
    now work for me like this ;)

    Code (CSharp):
    1. using System.Collections;
    2. using UnityEngine;
    3. using UnityEngine.SceneManagement;
    4.  
    5. public class levelTeleportation : MonoBehaviour {
    6.      
    7.     //wall teleportation particle
    8.     public GameObject wallteleportationpe;
    9.  
    10.     public string loadingLevel;
    11.  
    12.     private finalWall finalwallControl;
    13.     //private GameManagerLevels GMControl;
    14.  
    15.  
    16.     public float timeToLoad = 3;
    17.     private bool loadingLevelStart = false;
    18.          
    19.  
    20.  
    21.     // Start is called before the first frame update
    22.     void Start()
    23.     {
    24.         //GMControl = FindObjectOfType<GameManagerLevels>();      
    25.         finalwallControl = FindObjectOfType<finalWall>();
    26.         wallteleportationpe.SetActive(false);
    27.     }
    28.  
    29.  
    30.  
    31.     void OnCollisionEnter2D(Collision2D other)
    32.     {    
    33.  
    34.         if (other.gameObject.tag == "mainplayer")
    35.         {
    36.             loadingLevelStart = true;
    37.        
    38.             //wall teleportation particle
    39.             wallteleportationpe.SetActive(true);            
    40.         }                  
    41.  
    42.     }
    43.        
    44.  
    45.  
    46.     void pauseSceneLoading()
    47.     {
    48.         timeToLoad -= Time.deltaTime;
    49.         if (timeToLoad <= 0)
    50.         {
    51.             finalwallControl.checkscore500coll();
    52.         }
    53.     }
    54.  
    55.  
    56.  
    57.     void Update() {
    58.              
    59.         if(loadingLevelStart == true)
    60.         {
    61.         pauseSceneLoading();
    62.         }
    63.  
    64.  
    65.     }
    66.  
    67.  
    68. }