Search Unity

Start from the beginning?

Discussion in 'Immediate Mode GUI (IMGUI)' started by Nicky, Nov 20, 2007.

  1. Nicky

    Nicky

    Joined:
    Nov 12, 2007
    Posts:
    19
    I have never done anything related to scripting or gaming. I am interested in the process, but I need to start from the very beginning. I have set up my scene in unity for a first person walk through. There is no animation, I am basically just showing the model.

    I need to know how to set up a menu with play buttons and a brief description of controls prior to play time for exporting into a windows standalone. I want it to be creative, but I don't even know what my limits are!
     
  2. DaveyJJ

    DaveyJJ

    Joined:
    Mar 24, 2005
    Posts:
    1,558
    Menus are fairly simple to set up now and are detailed in the Unity manual located here ...

    file:///Applications/Unity/Unity.app/Contents/Documentation/Documentation/Manual/Game%20Interface%20Elements.html

    The simplest way to set up a game, in a very basic sort of way is as follows (at least to my mind) ...

    Create a small handful of scenes. Call them "Splash", "Instructions", "Game". You sound like you already have one called "Game" started. Make sure to open the build menu and drag all three in. Make sure that splash is scene 0 at the top (the first scene).

    The splash scene can be simply the camera looking at a flattened cube that has a texture (image) applied to it. The cube can be made "self-illuminating" so a light source isn't needed to 'see" the texture/graphic you attached to it.

    Add an empty game object to the scene and call it "ScriptHolder". Then write a simple script called "NextScene.js" that has a simple bit of code that says "if the player clicks anywhere, load (aka go to) the scene called "Instructions". Attach that to the Scriptholder object. Or create a GUI.Button and use the GUI features to make a button load the scene.

    The Instructions scene can be done just like the first. Flattened cube with graphic texture attached. This time it's a new graphic you've made with the instructions. New GUI script with new button to load the Game scene.

    In the game scene (that you have) add an empty game object and attached a new GUI script to it with a Quit button.

    That's a basic game for you.
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Sounds reasonable to me, although I'd rather use a GUITexture instead of cubes...that's pretty much exactly what they're for.

    --Eric
     
  4. Nicky

    Nicky

    Joined:
    Nov 12, 2007
    Posts:
    19
    I did exactly that... and it worked in Unity... but I get error messages in the windows standalone, and it wont run! The splash page opens, but thats it. I am wondering if there is something wrong with the script I put in? There is no error in Unity, only on the PC. I submitted the error, but I would like to try something different to see if I can get it to work. Any suggestions for changes?

    Here is what I used to go from splash page to menu:

    function OnGUI () {
    //Loads the level with index 1
    Application.LoadLevel (1);
    }


    And what I used for a button to enter game mode:

    function OnGUI () {
    // Make a background box
    GUI.Box (Rect (10,10,100,90), "");

    // Make the first button. If it is pressed, Application.LoadLevel(2) will be executed
    if (GUI.Button (Rect (20,40,80,20), "ENTER")) {
    Application.LoadLevel (2);
    }
    }
     
  5. DaveyJJ

    DaveyJJ

    Joined:
    Mar 24, 2005
    Posts:
    1,558
    Hmm, I wonder why that doesn't work? Here's one of my buttons ...

    Code (csharp):
    1.  
    2. if (GUI.Button (Rect (Screen.width / 2 - 160, Screen.height / 2 + 250,150,25), "Play Again")) {
    3.             Application.LoadLevel ("SelectLevel");
    4.         }
    5.  
    I always use the name of the scene to load ... that way if I ever fool around with the order of the levels in the build menu the link in the nav buttons won't change.

    Maybe someone else has an idea why this doesn't work for you.

    BTW, where's the button in the first one?? I'm not sure onGUI () allows that line of code.
     
  6. shaun

    shaun

    Joined:
    Mar 23, 2007
    Posts:
    728
    OnGUI() is called every frame, so Application.LoadLevel shouldn't be there without some kind of branch to stop it triggering each frameloop.
    It probably wont cause a serious problem until you start using DontDestroyOnLoad, but its not a good idea either way - and may be causing your windows build issue.
     
  7. Nicky

    Nicky

    Joined:
    Nov 12, 2007
    Posts:
    19
    I was using javascript.

    Actually, HQ got back to me, and it was something so easy!!!! I had transferred the files from the mac to the PC using a network, There is a bug in 2.0.1 that Windows games can't load scripting through a network connection. As soon as I transferred it to the PC harddrive, it ran perfectly.