Esempio n. 1
0
    void OnGUI()
    {
        // This function is being called once per event. This means
        // it can be called multiple times in one frame. Only in here
        // we can call the GUI class functions and no where else.

        // Each function needs a Rect. Rects hold 4 variables.
        // 2 for position (x,y) and 2 for size (width, height).
        // This defines where and how big the selected GUI
        // element will be.

        // I am pretty sure with each frame this method is called once
        // at the very start of the rendering proccess, so that it
        // can draw everything we asked on the screen.
        // If there is an event, it comes in and checks a few things.
        // Things like, did we press any of the buttons? Did we type
        // anything in a text box/text area? Did we move a slider?
        // In general, this is a pretty cool way to implement a gui.

        // Later on we are probably going to add a GUI skin as well.
        // It will allow us to mess around with the way everything
        // is shown.

        // Selected info Label
        GUI.Label(selectedRect, selected);

        // Credits info label
        GUI.Label(creditsRect, "Credits: " + GeneralMapLogic.credits);

        // Map name info label
        GUI.Label(nameRect, ImportMap.mapName);

        // Tower buttons
        if (GUI.Button(tower1Rect, "Tower 1"))
        {
            selected = "Tower 1";
        }

        if (GUI.Button(removeRect, "Remove Tower"))
        {
            selected = "Remove Tower";
        }

        // GUI events
        Event e = Event.current;

        if (e.isMouse && e.button == 0)
        {
            stInstance.SetSelectedTower(selected);
            if (selected == "Remove Tower")
            {
                stInstance.RemoveCommand();
            }
            else
            {
                stInstance.SpawnCommand();
            }
        }
    }