Deprecated: Assigning the return value of new by reference is deprecated in /nfs/c03/h01/mnt/55667/domains/blog.michaeljbowen.com/html/wp-settings.php on line 472

Deprecated: Assigning the return value of new by reference is deprecated in /nfs/c03/h01/mnt/55667/domains/blog.michaeljbowen.com/html/wp-settings.php on line 487

Deprecated: Assigning the return value of new by reference is deprecated in /nfs/c03/h01/mnt/55667/domains/blog.michaeljbowen.com/html/wp-settings.php on line 494

Deprecated: Assigning the return value of new by reference is deprecated in /nfs/c03/h01/mnt/55667/domains/blog.michaeljbowen.com/html/wp-settings.php on line 530

Deprecated: Assigning the return value of new by reference is deprecated in /nfs/c03/h01/mnt/55667/domains/blog.michaeljbowen.com/html/wp-includes/cache.php on line 103

Deprecated: Assigning the return value of new by reference is deprecated in /nfs/c03/h01/mnt/55667/domains/blog.michaeljbowen.com/html/wp-includes/query.php on line 21

Deprecated: Assigning the return value of new by reference is deprecated in /nfs/c03/h01/mnt/55667/domains/blog.michaeljbowen.com/html/wp-includes/theme.php on line 623
michaeljbowen.com » Using C# with Unity 3D to achieve code completion (intellisense)
Home > C#, Unity 3D > Using C# with Unity 3D to achieve code completion (intellisense)

Using C# with Unity 3D to achieve code completion (intellisense)

August 8th, 2009

I’ve been playing around with Unity 3D lately, and its pretty awesome.  Its not very difficult to make the leap from Flash to Unity.  However, one detractor to Unity is its poor coding environment.

As a Flash programmer, I’m very spoiled by several of the development environments available to me.  FlashDevelop, Flex, etc. all provide intelligent editors that give me code completion.  Unity’s built in editor does not have this feature.  Once you get used to code completion, you can never go back to a plain text editor!

The good news is that you can use Visual C# 2008 Express for all of your Unity coding needs, and its totally free!  Thanks, Bill Gates.

Below are the steps to set up your environment.  Have fun.  Don’t say I never gave you anything.

One time setup:

1. Download Visual C# 2008 Express for free:
http://www.microsoft.com/express/vcsharp/

2. Install it.  ;)

3. Download the following file, which is needed for tool tips as you edit in C#.
UnityDocs.zip
Place the 2 XML files here:
C:\Program Files\Unity\Editor\Data\lib
(or wherever you installed Unity)

Repeat for each project:

1. When you create a new Unity 3D project, you need to create a new C# project somewhere in the Assets/ directory.  It can be right in Assets/, or you can make a sub directory.  Making a sub directory might be cleaner as C# will create solution files, etc.  Use “Empty Project” as your project type in C#.

2. Add a reference to the Unity dll files in your C# project.
In C#’s Solution Explorer panel (on the right), right-click the project and choose “Add Reference”.
Browse to and add UnityEngine.dll.
(you can add the editor dll as well if you are going to write editor code)

3. Create new class files from within C#.  If you do it from Unity, they don’t show up automatically in your C# project (there is probably a way to add them, but I don’t know it).

That’s it!
Code completion, tool tips, hints… it’s all there.

C#, Unity 3D ,

  1. August 10th, 2009 at 10:57 | #1

    I don’t know what coding preference you have, but you can also use UnityDevelop( http://technology.blurst.com/unitydevelop-javascript-editor/ )
    to program. It is just an extension of FlashDevelop, so it is a little more familiar. I have used flash a lot in the past as well, so staying with something similar to actionscript/javascript is an easier transition. Have you tried this out?

  2. August 10th, 2009 at 13:05 | #2

    Scott, I have indeed tried out UnityDevelop. I love FlashDevelop, so I’m right at home. However, one concern is that UnityDevelop could disappear at any time, and has no support. Also, using C# allows one to reuse a lot of code for targeting another platform… say XNA maybe.

  3. Andrew Rapo
    August 12th, 2009 at 16:30 | #3

    This is really helpful. Do you know of a way to add a class template to VS C# to create blank Unity-friendly class stubs?

    Thanks.

  4. Andrew Rapo
    August 12th, 2009 at 20:25 | #4

    I found that if you create a script in Unity, you can drag it from the file system into VS and it will then show up in your project.

    I would like to know how to set up Unity/VC so that double-clicking on a file in Unity will open it in the VC project - at the right line number. Making VC the default editor doesn’t quite do it.

  5. August 21st, 2009 at 22:51 | #5

    If you want to include a .cs file(s) created in Unity in your Visual C# project. First click the ‘Show All Files’ button at the top of the Solution Explorer, then you will see all files within that folder, items not in the project will appear white. Right click on the required files or folders and select ‘Include in Project’.

  6. August 22nd, 2009 at 07:56 | #6

    @Devin Reimer
    Thanks for the info.

  1. No trackbacks yet.