torsdag 31. mars 2011

A quick Unity/Boo tip.

If you've been writing any code in Unity 3D you've probably encountered the GetComponent(s) function. For the uninitiated, it allows to you access other components attached to the same GameObject.

This is the usual way to do it:
other = GetComponent[of OtherScript]()
other.DoWhatever()

When I first started out with Boo, this sort of bothered me. I use Boo to limit the amount of brackets and semicolons in my life, so I decided to read up on how Boo does Generics. What I found was that you could omit the square-brackets.

other = GetComponent of OtherScript()
other.DoWhatever()

Now that looks much, much better.

Don't sleep on these links:
http://groups.google.com/group/boolang/browse_thread/thread/ff5a4fa8166adc82/bbb42c9405e75e75
http://msdn.microsoft.com/en-us/library/ms172192.aspx

søndag 27. mars 2011

I Did a thing!



But what is it? It's a prototype of a novel character controller. You can probably guess where the inspiration came from.. I went through a lot of different solutions before landing on the one you're seeing. I may go into detail about the different approaches one can take, later. 

Right arrow moves. Spacebar jumps.

Thanks to Unity the hardest part was integrating the webplayer with blogspot. Seems to work best with Firefox, and not at all with Safari.

lørdag 26. mars 2011

Getting started with Boo, using Unity 3D.



For this tutorial I am going to assume no prior knowledge of the Boo programming language, or for that matter programming. My main goal is to get you started learning a cool language(Boo), in a great environment (Unity).


What makes Boo so special? 
You have probably heard about Java, C#,javascript. At least in passing. 
These are programming languages, like Boo. But if you have ever written C you will immediately see quite a few differences. 
Boo does things quite differently from other languages. 
In fact it borrows a lot of its features from Python. A language often praised for being easy to read, maintain and write. And you can have all that power. In Unity (or anywhere). Right now.





1. Configuring Unity 3D 

The first thing you need to do is set Mono Develop as your default editor.
Select “Unity” >> “Preferences” and from the drop down list select “MonoDevelop”







You may need to browse to your Unity 3D installation directory and manually select the “MonoDevelop” executable.


In your Unity project tab. Left click, select Create and then “Boo Script”

Rename your new script to HelloWorld. Your project directory should look like this:

To make this all come together we have to tell MonoDevelop about this new script. So Select Assets in the menubar, and select "Sync MonoDevelop Project"

That's it, welcome to your new IDE, and we're ready to start writing Boo scripts!





2. Diving into Boo
Mono Develop now lives in your project directory. On the right side you can navigate your projects script assets. Locate the HelloWorld Boo file you just created and open it with MonoDevelop
Your window should look something like this: (I may be using a different theme than you)

Essentially you have your code view on the left side, and your project view on the right side. I am not going to cover all the features of MonoDevelop itself in this post. That's several posts for later.

Now you need to change the line, that says

class NewBehaviourScript (MonoBehaviour):
To
class HelloWorld (MonoBehaviour):
And change the lines that say
def Start():
pass
To:
def Start():
Debug.Log(“Hello World”!)

So what have we done here? We have told the compiler (the program that turns your Boo code into something the computer can deal with) that we want it to prepare our Unity tools for us. By saying

import UnityEngine

We have named our class HelloWorld. What's a class you might ask? Well that's not important right now. Just stay with me. But your class name needs to be the same as your script name. And since our script is called “HelloWorld.boo” the class needs to be called “HelloWorld”

On the subsequent lines, two functions are declared. “Start” and “Update”. Since our Boo code runs in the Unity environment most of what I have just said is only relevant to using Boo with Unity3D. So this code will probably not work (at least as intended) when ran outside Unity.

In Bo we declare functions with the keyword called “def” short for define. Followed by the function name, then a colon.
def MyFunction:
But a function is no good unless it's doing something. That's where our new Start function comes in.
As for
def Start ():
Debug.Log(“Hello World”)

You can probably guess what this does right?
Start..Debug..Log.."Hello World"
It would be a reasonable guess to assume that this would Log “Hello World” somewhere when run. Which is exactly what it does.


3. Running it!
In the Unity 3D environment your Start function is automatically run when your script starts running, when it's attached to a active gameObject. So create a new gameObject in Unity, either a Cube or for that matter any old model you have around. And drag your new script onto it.
When you now start Unity you should see “Hello World” in your log window. If you don't have a log window, open it from “Window”>>”Console”


Now click Run in Unity, and you should see “Hello World” in your console.

4.Resources
If you are entirely new to the concept of programming, this is probably quite confusing. But I promise that you are just a few minor epiphanies away from getting it. It just takes a little bit of time. But now you are at least ready to start your journey. I suggest checking out some more tutorials, you will find tons of resources in this thread:
http://forum.unity3d.com/threads/72458-Official-Boo-Scripting-Resource-Thread