dup of http://answers.unity3d.com/questions/1288679/how-to-run-a-script-twice-in-a-scene-2.html
How to run a script twice in a scene
Hey,
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);
StartCoroutine(Example());
circularSilder.fillAmount = 0f;
}
public IEnumerator Example()
{
print(Time.time);
yield return new WaitForSeconds(4);
//fade it out
CanvasGroup canvasGroup = GetComponent<CanvasGroup>();
while (canvasGroup.alpha > 0)
{
canvasGroup.alpha -= Time.deltaTime / fadeTime;
yield return null;
}
DestroyObject(loadingBar);
print("Loaded Store");
loadingBar.enabled = false;
playMenu.enabled = false;
money.enabled = true;
Time.timeScale = 1;
}
public void Update()
{
circularSilder.fillAmount += Time.deltaTime / loadingTime;
}
}
Follow this Question
Related Questions
Opening Door pressing a key (keyboard or pad) 1 Answer
How to run a script twice in a scene 2 Answers
how can i save highest played level?,how can i save number of highest played level? 0 Answers
how to fix countdown bug after reset level? 0 Answers
How can I act the scrip that in the FirstPersonCharacter? 0 Answers