i'm trying to get two MMTools componentsto show the SaveSystem loading progress value,
The components have a SetProgress(float) method by wich you can update the progress bar and percentage.
both ui elements and the scripts are on the scene fader canvas.
my problem is that i am not using a loading scene, and if i call SaveSystem.currentAsyncOperation.progress outside a loading scene, i get this error:
Code: Select all
NullReferenceException: Object reference not set to an instance of an object
LoadingScreenProgressBar+<UpdateProgressBar>d__5.MoveNext ()
this is the code for my loading bar
Code: Select all
using System.Collections;
using UnityEngine;
using PixelCrushers;
using MoreMountains.Tools;
public class LoadingScreenProgressBar : MonoBehaviour
{
//MM tools references
public MMSceneLoadingImageProgress loadingImage;
public MMSceneLoadingTextProgress loadingText;
// params
private float progressValue;
public void UpdateBar() {StartCoroutine(UpdateProgressBar()); }
public IEnumerator UpdateProgressBar()
{
while (!SaveSystem.currentAsyncOperation.isDone)
{
progressValue = SaveSystem.currentAsyncOperation.progress;
Debug.LogWarning("progress: " + SaveSystem.currentAsyncOperation.progress);
if (loadingImage)
{
loadingImage.SetProgress(progressValue);
}
if (loadingText)
{
loadingText.SetProgress(progressValue);
}
yield return null;
}
}
}