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

Ingen kommentarer:

Legg inn en kommentar