Oct 282011
 

Like the rest of the Megabite series, I will be instructing by using Unity3d, which has proved itself to me time and again over the past few projects.  Most recently, I was able to use the trial of Unity Android to get myself published onto the Android Market, and though in my case the game was nearly finished for its format as a web-based game, I merely had to switch platforms within the settings and alter a few lines of code to add things such as accelerometer controls.

In this article, I will be talking about the basics of going from “New Project” to “Hey check out the app I just published”.

To begin, you will need a trial copy of Unity3d Android at the minimum, which can be found here.  The licensed copies of the software or the Pro version are $400 or $1500 dollars respectively (which may seem steep until you get an idea of the features and differences), but a trial is enough to get yourself started and even get a working game ready for publication.  If you are on a trial copy, you will see “trial copy” watermarked in small text at the bottom-right portion of the finished product, but the software isn’t limited in any other respect that I’ve come across so far.

You should download and install the Android SDK as well, and update it with the packages you are aiming to target.  While this tutorial will not cover the SDK inner-workings, Google has a great deal of pre-existing documentation on the basics if you choose to use it.  For our purposes, we don’t need to spend much more time than to install it.

Getting your game together

If you have existing code, you may see some errors pop up if you were lazy in the way you declared variables (like I was).  if you have a script that contains something like:

var myVariable;

You will likely see a warning that forces you to declare what type of variable you are creating.  Since you should already know what it is you’re trying to DO with this variable, this isn’t a big issue.  You simply define it as a string, integer, float, game object, or whatever you need.

var myVariable : String;

For me, this was simply a wake-up call that let me know I should be more specific.  Not to mention, it’s a good habit to develop anyway and it makes your code more readable when you go back to decipher work from earlier.  Suffice it to say that Android development was just a slight bit pickier in how things are read, but you can see it wasn’t a deal-breaker.

If this is your first time using Unity to develop, I suggest reading through earlier posts in this series to get a basic understanding of Unity development as a whole before you dive into the deep end.  In fact, we’re going to import the project that is still standing from #2 in the series and use that project to develop our first APK file.

We’ll start by switching the platform over to Android, as you can see on the left (File -> Build Settings). Once you’ve selected it, you simply click the button beneath to begin the automatic process.  Unity converts whatever it needs to behind-the-scenes while you wait.

Once the process is complete, you will see if there are any errors that might need to be handled.  In the case of the Megabite project, there were not – so we can move on.

Because we are now developing for a different resolution and such, you will notice that your “game” tab has some new view switching options.  Obviously Android has many different hardware setups, so you should keep these in mind as you test your game in the player.  Sometimes seeing what the game looks like in a different aspect will remind you about hiccups that may have occurred in your calculations or display setup.

What we’re going to do here is a landscape setup, so you will want to open your player settings to choose these options.  Go to Edit -> Project Settings -> Player, and you will see the different options available in the new Android tab.

While you’re in here, you can alter things such as your icon (will display on the Android device home screen or within the applications menu), the Product (game) name, and your company name.  Under Resolution and Presentation, I will choose “Landscape Left”, which seems the most compatible and common landscape option.

Fair warning: I did attempt to change some of the settings within “Other Settings” when I first published GIRType, and simply ended up crashing my phone.  I would suggest you stick to the default options unless you know specifically what you are choosing, but you should be sure to change these boxes when applicable:

For your first go-round, the Identifier is the important option.  The version number and version code will need to be raised for each publication to the market (or else google will give you an error), but to test things locally you can leave them unchanged for now.

Lastly, the publishing settings.  While the terminology here might be new or seemingly complicated, you really just need to create 2 passwords here.  Check the box for “Create new Keystore” and then browse – Unity will create a file and save it to the system.  Once done, you need to create a password for this keystone and confirm it.

The pull-down box for the “Alias” will have an option to create a new key, which will allow you to put in more information.  Here you will create a second password and re-enter it on the publication tab when finished.

Once all these basic things are accomplished, you will immediately be able to build the project into an APK file.  Open the build settings once more (be sure your scene is in the scene list.  If it isn’t, open your scene and hit “add current” and you’ll see it listed) and hit the Build button.  You’ll be prompted during the process to select your base folder for the Android SDK if Unity doesn’t automatically find it, but you can move on once selected.

Follow me onto the next page and we’ll get that file up and running.

 Leave a Reply

Connect with Facebook