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. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

How to create a fake loading bar???**SOLVED**

Discussion in 'Scripting' started by Tonguesten, Jun 19, 2018.

  1. Tonguesten

    Tonguesten

    Joined:
    Aug 15, 2017
    Posts:
    24
    It may weird to see I'm asking this sort of question, but a regular loading screen that display actual loading progress is TOO FAST for my game due to its small size. Now I wanted to make a fake loading bar, but I don't know how to do it. Plz help.
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    ... so the game would be ready to go, but you want the player to wait for no reason to watch the bar?
     
  3. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,596
    Presumably, you are wanting to test the loading bar to show it will work when the game does, in fact, take longer to load?

    In which case, you would need to make the requisite change(s) in your game loader code to pretend that it is taking longer than it actually needs.
     
  4. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,383
    I'm certain I've never ever had a request to arbitrarily make something take longer to load for absolutely no reason other than taking longer to load.
     
  5. GeorgeCH

    GeorgeCH

    Joined:
    Oct 5, 2016
    Posts:
    222
    Depends quite heavily on how you're implementing the real progress bar underneath it all (e.g., if there's actual loading of a scene going on or if we're just talking about an image with a loading progress bar that actually reflects no real loading progress).

    Either way, I'd suggest throwing a coroutine somewhere into it to make the game wait for X number of seconds, e.g.,:

    Code (CSharp):
    1. IEnumerator WaitForLoadingBar(float seconds)
    2. {
    3.      float currentTime = seconds;
    4.  
    5.      while (currentTime > 0)
    6.      {
    7.           currentTime -= Time.deltaTime;
    8.           yield return null;
    9.      }
    10.  
    11.      Debug.Log(seconds + " seconds have passed! And I'm done waiting!");
    12. }
     
  6. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Just create any animation you want, run it for as long as you want, and then continue with your game when ready.
     
    Kurt-Dekker and FranklinLisboa like this.
  7. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Tossing out one other idea -- you could check the coroutine for progress, and compare it to a minimum time. Use whichever is smaller of the two.
     
    PetPumpkin likes this.
  8. Tonguesten

    Tonguesten

    Joined:
    Aug 15, 2017
    Posts:
    24
    Okay you guys know what, screw it, I think my game doesn't need that sort of feature.
     
    PetPumpkin, xVergilx and Doug_B like this.
  9. tolikjan

    tolikjan

    Joined:
    Jul 18, 2021
    Posts:
    1

    Hi,

    I was facing the same issue for my first game, and here is mine solution.


    Code (CSharp):
    1. public async void LoadScene(string sceneName)
    2.     {
    3.         _realProgress = 0.0f;
    4.         _fakeProgress = 0.0f;
    5.         _loadingSlider.value = 0.0f;
    6.  
    7.         // Start loading scene but not activate it
    8.         var scene = SceneManager.LoadSceneAsync(sceneName);
    9.         scene.allowSceneActivation = false;
    10.  
    11.         do
    12.         {
    13.             await Task.Delay(100); // Timeout between the 'ticks' of progress bar
    14.             _fakeProgress = _fakeProgress + Random.Range(0.01f, 0.1f); // Value of one 'tick'
    15.             _progressTextValue.text = _fakeProgress.ToString("0.00%"); // Displaying progress in %
    16.             _loadingSlider.value = _fakeProgress;
    17.         } while (_fakeProgress < 0.9f);
    18. // Using Random we can have the progress between 0.91 and 1.0 in the end of loop...
    19.  
    20.         //...so, set the progress bar value to 100%
    21.         _loadingSlider.value = 1.0f;
    22.         _progressTextValue.text = "100.00%";
    23.  
    24.         // Meanwhile on the background we checking the real progress
    25.         do
    26.         {
    27.             _realProgress = scene.progress;
    28.         } while (_realProgress < 0.9f); // In Unity scene progress always between 0 and 0.9 ¯\_(ツ)_/¯
    29.  
    30.         scene.allowSceneActivation = true; // Now, activate the scene
    31.     }
    Hope, it'll help for other people seeking for answer to similar problems.

    Thanks, and have a great development time all.