How to run a script twice in a scene


I’ve got a scene and it’s basically a store, and I got a script (in C#) that disables a canvas until the loading screen has finished, when I run it for the first time it works perfectly, but when I click a back button that I implemented in the game and go back to the store scene the script that disables the canvas does not run.

My only guesses are is that unity does not run a script when it’s already been run, is there a way around that?

Thanks, Nathan.

Here’s my script that does the job for me in case you need it:

using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 using System.Diagnostics;
 public class ProgressBar : MonoBehaviour
     public Image circularSilder;            
     public float time;
     public Canvas loadingBar;
     public Canvas playMenu;
     public Canvas money;
     private float loadingTime;
     public float fadeTime;
     public void Start()
         loadingTime = Random.Range(1f, 4f);
         circularSilder.fillAmount = 0f;
     public IEnumerator Example()
         yield return new WaitForSeconds(4);
         //fade it out
         CanvasGroup canvasGroup = GetComponent<CanvasGroup>();
         while (canvasGroup.alpha > 0)
             canvasGroup.alpha -= Time.deltaTime / fadeTime;
             yield return null;
         print("Loaded Store");
         loadingBar.enabled = false;
         playMenu.enabled = false;
         money.enabled = true;
         Time.timeScale = 1;
     public void Update()
         circularSilder.fillAmount += Time.deltaTime / loadingTime;

my guess is that you have to call the ienumerator again

Hello Skypiggy,

Your problem is that you can only call the Start() method once per time the scene is loaded, you can use OnEnabled() to bypass this as it has nearly the same propertys as Start() (being that as soon as the gameObject and script are enabled it will run) but it can be called multiple times per scene load.

Or you could use a public void MethodNameHere() so that you can call the method from another script in the same scene or a button press.

Goodluck, from tiggy02.