Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
This question was closed Dec 21, 2016 at 02:43 PM by Landern for the following reason:

dup of http://answers.unity3d.com/questions/1288679/how-to-run-a-script-twice-in-a-scene-2.html

avatar image
0
Question by Nathan1258 · Dec 21, 2016 at 12:34 PM · scripting problemscript.canvasruntimescene-loading

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;
 
     }
 }
 
 
Comment
Comments Locked
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

104 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges