Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Instantiate not working through window

Discussion in 'Scripting' started by Ded_Hed_Hyde, Apr 2, 2014.

  1. Ded_Hed_Hyde

    Ded_Hed_Hyde

    Joined:
    Mar 10, 2014
    Posts:
    22
    Tried posting in answers but it wouldn't let me. So here goes...
    Okay I'm trying to get an object to Instantiate. I have all the prefabs set up properly. Basically I want a window to pop up and allow the player to build a unit. Only I get this error:

    NullReferenceException: Object reference not set to an instance of an object


    if (dockGuiOn == true)//will check if true
    {
    // Register the window. Notice the 3rd parameter
    windowRect = GUI.Window (0, windowRect, dockWindow, "Dock Menu");
    }
    }
    //Make the contents of the dock window above
    function dockWindow (windowID : int)
    {
    GUI.BringWindowToFront(windowID);
    GUI.FocusWindow(windowID);

    //build rigs as construct location
    if(GUI.Button (Rect(30,20,55,16), "Build Rig"))
    {
    print("Hit Build Rig");
    var drillShipRig : Transform;
    drillShipRig = Instantiate (drillShipRig, transform.position, transform.rotation);
    }
    GUI.Button (Rect(15,40,90,16), "Bid on Contract");
    GUI.Button (Rect(25,60,75,16), "Hire Workers");
    GUI.Button (Rect(25,80,73,16), "Upgrade Rig");
    GUI.Button (Rect(25,100,70,16), "Stack Rig");
    GUI.Button (Rect(10,120,100,16), "Cold Stack Rig");

    if(GUI.Button (Rect(1,1,16,16), closeTexture))
    dockGuiOn = false;;
    }


    The part that isn't working is the section

    if(GUI.Button (Rect(30,20,55,16), "Build Rig"))
    {
    print("Hit Build Rig");
    var drillShipRig : Transform;
    drillShipRig = Instantiate (drillShipRig, transform.position, transform.rotation);

    Sorry if the formatting is horrible but I can't figure out how to get the tags to work properly. I've used this in other programs but can't figure it out for the life of me. Any help is greatly appreciated.
     
  2. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,514
    Which line is that error referring to? That'll tell you which of the objects is null, and that'll tell you where to look for the cause.

    Also, with extra spaces added so it'll show:
    Code (csharp):
    1. [ code ]
    2. ...
    3. [ /code ]
     
  3. Ded_Hed_Hyde

    Ded_Hed_Hyde

    Joined:
    Mar 10, 2014
    Posts:
    22
    Nevermind folks! Figured it out!!!!