Search Unity

New to Unity need a quick primer

Discussion in 'Scripting' started by oronll, Nov 16, 2009.

  1. oronll

    oronll

    Joined:
    Nov 16, 2009
    Posts:
    4
    Im not new to programming but I am new to Unity.

    So here is my question.

    How do you set a main game loop and global variables? I know I could set a dummy object but does that get cleared when you load a new scene?




    Thanks in advance.
     
  2. Troy-Dawson

    Troy-Dawson

    Joined:
    Nov 2, 2009
    Posts:
    120
  3. oronll

    oronll

    Joined:
    Nov 16, 2009
    Posts:
    4
    yeah but that is not good practice.

    I do not want to have keep repeating functions. Attaching countless scripts to every object.


    my main question is how I am suppose to keep my data and functions from one scene to the next? Like number of lives and score from level to level.

    AKA my global variables. There has to be a way to set them at the start of the game and keep them through out.
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It is in Unity, where there isn't really any such thing as a "main loop". You should do some of the tutorials (like the third-person platformer) so you can get a sense of how things work.

    --Eric
     
  5. oronll

    oronll

    Joined:
    Nov 16, 2009
    Posts:
    4
    So basically if I load a new scene I need to pass all the variables I want to keep from the scene I am in to the new scene? that seems excessive.. but I guess it would work if that is how it must be.
     
  6. cosmicmesh

    cosmicmesh

    Joined:
    Mar 19, 2009
    Posts:
    61
  7. oronll

    oronll

    Joined:
    Nov 16, 2009
    Posts:
    4
    ok .. yes that is what I am looking for.

    Thank You