How to know if a point is inside a polygon

April 16 | 15

Here’s a quick code snippet to know if given a point, the point is inside an array of polygon vertices. Based on the crossing number algorithm.


This can also be extended to 3D space if necessary, but that’s for the reader.

Open Match-3. Developed in Unity

April 14 | 15

So I had this project for long time stored and didn’t know what to do with it so what a better idea than releasing it!.

Hopefully the community will learn from it, and if you find any better way of doing certain things I’ll be more than happy to receive some feedback!

This project is released under the MIT license, you can do whatever you want with it :).

As the title says is a match 3 that works in Unity. 4.x and 5.x. it contains:

  • Generates a move if the board doesn’t have any more moves left.
  • Supports any amount of gems (for the time being I just added 5 types of gems).
  • Works with any board size (width x height)
  • Generates an “explosion” effect when 3 or more adjacent gems are clicked.
  • Generates a hint (depending on a time in secs set in the inspector) of the largest adjacent gems.
  • Support for score multiplier when you click on several correctly adjacent gems before the hint kicks in.

Here are some screenshots of the game:

Screen Shot 2015-04-14 at 15.03.57















Also supporting any width x height (17×18) in this case.

Screen Shot 2015-04-14 at 15.05.21












Finally in order to modify certain parameters of the game, just click over the main camera object and set the desired values inside GameManager component.

Screen Shot 2015-04-14 at 15.07.54












Liked the project?, Here!, fork it!


Like this post?, feel free to subscribe to my posts, I’ll keep you posted on anything that I write :).


Any comments/suggestions/feedback let me know :).


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 :D

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

Quick example on how to use it:


Mixing GUILayout and GUI and making them coexist together (Useful when editor scripting)

January 20 | 15


Even tho Unity 4.6 has come out with the new Unity GUI, you still need sometimes to use the old legacy GUI and GUILayout API specially if you are working with editor scripting.

Being said that, DONT use GUI/GUILayout functions for GUI on your projects (except editor scripting) if you are using Unity 4.6+; using GUI/GUILayout  in your actual game is slow and consumes lots of draw calls!.


So now that everything is clear here’s a little bit o what happened:

I am programming a new tool for the asset store and I was needing to display some textures in the inspector view (after all the GUI was written using GUILayout…), but Unfortunately “EditorGUI.DrawPreviewTexture()” doesnt have a layouted version :/ and I didnt wanted to do the whole same thing again using plain GUI. so I came up with an interesting idea that I wanted to share on making GUI and GUILayout coexist in the same GUI :).

So I’m going to expose having GUILayout code and inserting GUI code. and making them both coexist in the same Repaint().


Mixing  GUILayout with GUI

this happens when we have lots of GUILayout calls same as when we are building our window with pure GUILayout calls and there are some functions that are available only for GUI.

In my case I was wanting to create a tool for displaying the materials’ textures of any given object and some small info:

So the tool is organized and also looks like this:













and it even maintains its proportions! :D













So how do I do it?, its actually pretty simple, basically what I create is an area (with GUILayout) and inside the area I create a ScrollView (also with GUILayout) and then in the inside we put all our GUI (relative to the Area we created and not to the window) and we fill everything with GUILayout.Spaces(px)!


Sounds complex? its not at all!, trust me :),  let me show you a really simple code:

Basically what we need to do is to create an empty area from the GUILayout space and fill it with “spaces” that are consistent with what we draw on the GUI space. Let me draw it for you:


















Mixing GUI with GUILayout.

Mixing GUI with GUILayout is basically the same process you just have to take into account the space consumed by the GUILayout and then just offset the other GUI objects so they can coexist.

I’ll leave this part to the reader tho.


Like this post?, feel free to subscribe to my posts, I’ll keep you posted on anything that I write :).

Any comments/suggestions/feedback let me know :).