If you’ve done any game development or researched game development platforms, you’re probably familiar with Unity3D. Unity 5 was recently announced, and if you haven’t yet downloaded it, get it now. Really, I’ll wait. You owe it to yourself to play with software this awesome. And you can’t beat the price (free).
One of the (many) things that makes Unity3D so incredible is the support for multiple languages, one of which is C#. When you install Unity3D for Windows, MonoDevelop comes as the built-in code editor, and while MonoDevelop is a powerful IDE, if you’re developing for Windows, you’re most likely accustomed to using Visual Studio. Previously, there was a nice little add-in tool you could purchase called UnityVS which enabled development in Visual Studio. The bad news is that UnityVS is no longer available. The good news is that Microsoft purchased the company and now the Visual Studio 2013 Tools for Unity are completely free!
Here’s a quick walkthrough on how to configure Unity to use Visual Studio 2013 as the external editor. As you build projects and develop scripts in Unity, the Console window will provide feedback. In the image shown following, the Console is indicating that I have a script that is throwing an error:
If I double-click the error, Unity sends me over to MonoDevelop to help locate the problem. In the following screenshot, you can see the MonoDevelop IDE, and while it opened the scripts from my project on tabs, it didn’t take me where I needed to be – in my “InstanceAnObject” script. I had to click the tab to get over there, and while the Console window told me the error is on line 44, there isn’t much indication here of what the problem is without jumping back and forth.
Let’s fix it! Fire up Visual Studio 2013 and from the Tools menu, select Extensions and Updates.
When the Extensions and Updates window opens up, select Online on the left side of the window, and then type Unity into the search box at the top right. The search results will fill in and you’ll see the Visual Studio 2013 Tools for Unity item in the list. Click the Download button to download the .msi installer. Once downloaded, you should exit Visual Studio before installing the extension by double-clicking the .msi file.
Now that the tools are installed, hop back over to Unity 5, and select Preferences from the Edit menu.
The Preferences window offers several pages of options. The one we’re concerned with is the External Tools item. Once you’re on the External Tools page, the very first drop-down you see is External Script editor. By opening the drop-down, you may see a few items in there, but likely not Visual Studio 2013, so let’s add it. Select Browse from the drop-down, then navigate to your install location for Visual Studio 2013. If you installed VS with the defaults, it’s likely located at C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE. Select the devenv.exe file and click Open. The drop-down will now add Visual Studio 2013 to the list of available editors.
Now when I go back to the Unity Console window and double-click the error, Visual Studio is launched, I am taken right to the script file containing the error, and the familiar red squiggly underline lets me know right where the problem is.
If I hover my mouse over the underlined code, I see the long description of the error to try and help me figure out the resolution.
In this case, the script was using Unity’s version of Random, which does not contain the NextDouble() method like C#’s. To clarify that I want to use the C# Random, I just added “System.” prior to the Random argument in the method signature.
If I save my script file and head back over to Unity, my Console window updates and no longer shows any errors, so I know I’m good to go.
MonoDevelop is a great tool that is more than adequate for developing Unity3D scripts, but if you’ve been using Visual Studio for a long time, it’s easy to make use of your familiar toolset while you’re developing the next great game.