Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by lcfr822 · Mar 29, 2015 at 08:45 AM · uitimer-scriptmainmenufadeinlevelload

Why is my timer not starting after reloading a level?

I have looked around for answers, but unfortunately have found none. I have a fade-in in my menu level based on a colored plane in front the main camera. This works fine the first time I load the game to the Main Menu, but when I go back to the Main Menu from the gameplay UI, the fade never starts, but the music and buttons are functioning nonetheless. Any help would be greatly appreciated! UPDATE: I know very little about Javascript, trying to learn it a little.

 #pragma strict
 var timer : float = 5.0f;
 function Awake(){
 }
 
 function Start () {
     renderer.material.color.a = 1;
 
 }
 
 function Update () {
     timer = timer - Time.deltaTime;
     if(timer > 0){
         renderer.material.color.a -= 0.1 * Time.deltaTime;
     }
     if(timer <= 0){
         timer = 0;
     }
 }
Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by MakakWasTaken · Mar 29, 2015 at 10:30 AM

Try this instead:

 function Update () {
      renderer.material.color.a = Mathf.MoveTowards(renderer.material.color.a,0,Time.deltaTime * 0.1);
  }
Comment
Add comment · Show 5 · Share
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
avatar image lcfr822 · Mar 29, 2015 at 03:24 PM 0
Share

Thank you for your response. I tried the script change, it did work as far as the fade, but it still doesn't happen when I go back to the level the fade is supposed to occur in. The fade occurs in the main menu level. Here is what's going on.

  1. Fade in to main menu.

  2. Load gameplay level.

  3. Quit to main menu (GUI Function).

  4. $$anonymous$$ain $$anonymous$$enu buttons and music function, but the screen does not fade in, so I can't see them.

avatar image MakakWasTaken · Mar 29, 2015 at 03:32 PM 0
Share

Try this ins$$anonymous$$d:

 function OnLevelWasLoaded () {
     Fade(true);
 }

 var isDone : boolean;

 function LoadLevel(name : String) {
     Fade(false);
     while (!isDone) {
         yield;
     }
     Application.LoadLevel(name);
 }
 
 function Fade(Out : boolean) {
     isDone = false;
     while (renderer.material.color.a != 1) {
         if (Out) {
             renderer.material.color.a = $$anonymous$$athf.$$anonymous$$oveTowards(renderer.material.color.a,0,Time.deltaTime * 0.1);
         } else {
             renderer.material.color.a = $$anonymous$$athf.$$anonymous$$oveTowards(renderer.material.color.a,1,Time.deltaTime * 0.1);
         }
         yield;
     }
     isDone = true;
 }
avatar image lcfr822 · Mar 29, 2015 at 04:13 PM 0
Share

I think the issue may be with the object itself. None of the booleans change except for Done, which always starts as True.

avatar image lcfr822 · Mar 29, 2015 at 04:19 PM 0
Share

Scratch that, this section isn't being called:

   if (Out) {
                   Debug.Log("occur");
              renderer.material.color.a = $$anonymous$$athf.$$anonymous$$oveTowards(renderer.material.color.a,0,Time.deltaTime * 0.1);
          } 
avatar image MakakWasTaken · Mar 29, 2015 at 04:35 PM 0
Share

When you want to load a level you have to use LoadLevel ins$$anonymous$$d of Application.LoadLevel

avatar image
0

Answer by lcfr822 · Mar 29, 2015 at 04:34 PM

So this was all a stupid mistake, I had set Time.timescale to 0 in the pause menu, but had not set it back to 1 after clicking main menu. I fixed it by putting Time.timescale = 1f in function start(). Thank you for your help!

Comment
Add comment · Share
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

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity 5 - Time counter Up script (millisecond precision) UI 1 Answer

Lerp doesn't work with SetAlpha 1 Answer

Unity 5 UI GUI Text Canvas Screen Resolution Adaption Problem 2 Answers

Clock Script From Java to C# Help 1 Answer

How can I add a UI (Main Menu) with function. 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