Archive for March, 2015

Adding Transform.LookAt2D like it belongs to the Unity API

March 31 | 15

Unfortunately there is no Transform.LookAt2D in Unity as for now in Unity5. BUT with an extension method this can be added into the API quick and easy!.

Its pretty simple. We just need to have a namespace included wherever we want to use Transform.LookAt2D and thats pretty much!, here’s how:

Lets create the extension method for LookAt2D:

And then we just need to call it from any of our scripts as part of the Transform methods! here’s a quick example:

Quick, easy and clean!





Getting a random enum value and also be able to exclude some values

March 5 | 15

As the post says, in the game I am working on I needed to get a random value of an enumeration but on some cases I needed to exclude some values of the enumeration, so I came up with this small snippet of code that given an enum type and an array of enum excluded values it will return you a random value of the enumeration.

It works with any type of enum you create 😀

If you have a better way to do it _please_ let me know :).

Quick example on how to use it: