Thursday, 10 February 2011

Day 3 - Hello World!

Coming from a Flash web background (and having a crap broadband connection) I'm obsessed at having as small a size as possible when creating a game. One initial reservation I have of Unity 3D is just how big are these final game files going to get? The word "3D" implies to me megabytes of huge polygon-laden models but I'm sure I'm just being paranoid. Let's crack on...

The first thing all crap programmers do is create a Hello World program.So let's do that and we can publish the file to web and see just how big it is!

Again I am a complete novice at Unity so let's have a play together and see where we get...

1. Fire up Unity - a huge demo seems to load up for me. Far too complicated for beginners so let's ditch that.

2. MENU - File -> New Project....

3. Browse to somewhere you want to put your files and call the file "HelloWorld" - so something like
"C:\Users\myusername\Documents\HelloWorld". Click Create.

4. MENU - GameObject -> Create Empty  (WOW!)

5. In the Project Pane click the "Create" button and drop down to "JavaScript". A script name will appear.

6. Drag the script name onto the GameObject in the Hierarchy pane. This associates the Game Object with the script.

7. Open up the script i.e double click it. And enter the following....

function OnGUI () {
    // Make a background box
    GUI.Box (Rect (10,10,100,40), "Hello World!");
}

8.Best to save things now... MENU - FILE -> SAVE SCENE AS    then call your scene something like "helloScene1"

9. Double click your Scene in the Project pane to make sure it is selected.

10. Click the PLAY Arrow at the top of the screen.

The text HELLO WORLD with a blue box should appear! Bloody hell we're done it!

Ok so how big is this basic file going to be if we deploy it to web? My first guess was several hundred K as I expected lots of unused assets and functionality of Unity to be included in the build. Let's find out....

11. MENU - File-> Build Settings - click add current which will put your "helloScene1" scene into the build list

12. Click BUILD and select a place to put the output files. Once done goto the files and open the WebPlayer folder and double click the WebPlayer.html file. Your new creation can be seen in the Browser!

The GOOD NEWS! The UNITY file is only 43K! HURRAH!

That will do for today :-) Tomorrow we can analyse what we have done and work out what GameObject, Scenes and Scripts are all about.

No comments:

Post a Comment