Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Having trouble loading a scene...

Discussion in 'Scripting' started by 123fendas, Nov 27, 2015.

  1. 123fendas

    123fendas

    Joined:
    May 23, 2015
    Posts:
    44
  2. DaDonik

    DaDonik

    Joined:
    Jun 17, 2013
    Posts:
    258
    Application.LoadLevel is never called in your code.

    You set timeRemaining to 5 and then only ONCE subtract Time.deltaTime, which is usually a very small number.
    Remove the && press_enter == 0 in your if. Note that you still need to hit return a few dozen times until timeRemaining will be smaller than 0.
     
  3. 123fendas

    123fendas

    Joined:
    May 23, 2015
    Posts:
    44
    Well, how would I go around keeping updating timeRemaining to Time.deltaTime?
     
  4. DaDonik

    DaDonik

    Joined:
    Jun 17, 2013
    Posts:
    258
    I don't really know what you want to do, but i guess you want to count down 5 seconds from the time the user presses enter. If thats the case, replace your Update method with the following:
    Code (CSharp):
    1. void Update()
    2. {
    3.     if (Input.GetKeyDown(KeyCode.Return) && press_enter == 0)
    4.     {
    5.         press_enter = 1;
    6.         sprite_renderer.enabled = false;
    7.     }
    8.  
    9.     if (press_enter == 1)
    10.     {
    11.         timeRemaining -= Time.deltaTime;
    12.         if (timeRemaining < 0)
    13.         {
    14.             Application.LoadLevel("path");
    15.         }
    16.     }
    17. }
    And please use code tags in the future, don't post screenshots.
     
  5. 123fendas

    123fendas

    Joined:
    May 23, 2015
    Posts:
    44
    Thank you! Everything works now. I just didn't have the logic to do that if (press_enter == 1) code.

    Very well.