Author Topic: Tips for using Unity  (Read 7157 times)

Offline LordDenir

  • New Foal
  • *
  • Posts: 4
  • Gender: Male
  • Game Design student at Qantm College
Tips for using Unity
« on: 2012-September 20, 02:33:58 »
Unity is a very powerful engine for game development, much to the point that it has become a norm within the industry as much as the Unreal engine. To some, Unity seems intimidating but with a bit of advice and some self directed learning you can easily get the hang of it.

You can access the documentation here including manuals and the scripting reference
http://unity3d.com/support/documentation/

Unity supports a number of languages such as C#, javascript and boo. If you are somewhat new to programming I'd suggest starting with javascipt then later moving on to C# once you have a few games under your belt. I say that mainly since there is more support in the community for javascript than C#.

FAQ

1. Isn't Unity a 3D engine? I want to make a 2D game.
A: You can make a 2D game easily. Simply restrict all movement to the axis' you want and apply textures onto game objects with Transparent -> cutout -> diffuse type (in other words your png will remove the sections of the game object where there is alpha). You can also animate the textures as long as its in a sprite sheet, though you will need to have a animation script set up. Go here to get started on sprite sheet animation http://wiki.unity3d.com/index.php?title=Animating_Tiled_texture_-_Extended#JavaScript_-_AnimatedTextureExtendedUV.js

2. How much can I do without scripting?
A: Not much really, Unity does have standard open source assets and scripts you can use (such as 1st and 3rd person character controllers), but without scripting the most you could get is a 1st person game walking in a maze of unity boxes. Note that there is ONE way to avoid scripts in Unity but its a $150 unitypackage that emulates the Kismet system from UDK (Unreal Development Kit).

3. Is everything done in scripts?
A: Only if you want to do it the hard way. Unity allows you to access and reassign public variables in your scripts from the editor itself. There are a couple of traps here for beginners though:

Example for adjusting variables in the editor

public var walkSpeed : int = 0;

when this variable is applied in a movement script the player wouldn't move. Since we made it public we can use the editor.

FIRST make sure the script is either attached to a game object or a prefab(we'll discuss these later)
SECOND make sure the engine isn't in play mode. Unity actually uses 2 engines one for the editor and one for playing the game. When playing, if you alter a variable the change will not save. This can be useful for testing results of different values quickly, just be sure to record your values in a notepad and then change them in the editor mode.

Now we can discuss how prefabs work and why they are important. Lets say I want 100 cubes with movement scripts. I could spend a long time make 100 cubes and attaching the scripts individually OR I can make a prefab.

To make a prefab you can create a game object in the Hierarchy, then click and drag it into the project tab. From here I can attach my script and then just click and drag the prefab into my scene.

Now public vars and prefabs, what's so important? Well if I change a public var on a script attached to my original prefab, it will change that value for every instance of that prefab in the scene. If I change the value on an individual cube then it will only affect that one cube.

For example if I had 5 cubes instantiated from a prefab with a bouncing scripting holding a public variable called bounceSpeed. I could change the speed of all my cubes using the script on the prefab OR changing the variable on the cubes individually, I can have cubes bouncing at different speeds. In the future I may be posting my Crusher script for people to use freely which utilises this handy system. 

Unity has all the tools there to design your own systems, go out there and make some amazing editor based scripts.

ASK ME STUFF AND I'LL DO MY BEST TO ANSWER

 
« Last Edit: 2012-September 20, 02:49:02 by LordDenir »

Offline DuckOfDoom

  • Regular Member
  • **
  • Posts: 20
  • Gender: Male
  • (❍ᴥ❍)
Re: Tips for using Unity
« Reply #1 on: 2012-September 20, 03:28:47 »
Do you thing it's better to use built-in physics engine for handling physics for 2d games or to implement your own "real 2d"-style solution.

I'm not talking about this gamejam as coding the physics may be troublesome in such a short time. I mean in general, performance- and feel-wise, what is your opinion?

sorry for possible misprints, i broke the "j", "k" and "l" keys. =\

Offline LordDenir

  • New Foal
  • *
  • Posts: 4
  • Gender: Male
  • Game Design student at Qantm College
Re: Tips for using Unity
« Reply #2 on: 2012-September 20, 05:11:18 »
As a rule of thumb if you can fake the physics then do it. Although it really depends on what you're doing. If you are talking about gravity for instance you are better off coding it yourself. I've generally never had a performance issue with physics, only time I've lost frame rate was when I found that I was printing to the console 400 times a frame. In terms of feel it can be better to script it yourself primarily because you have more control over it. The First Person controller movement script in Unity is a great example of this. I really only use rigid bodies for registering collisions, raycasts, etc.

Physics is generally better used in something like a 3D game prototype where you control a rolling ball and ram into buildings.

Offline Palm

  • New Foal
  • *
  • Posts: 4
  • Blank flank
Re: Tips for using Unity
« Reply #3 on: 2012-September 20, 23:21:32 »
This is now a language war. >:( Learn it right from the start and do C#. Its can be a slightly bitchier language. but it only does that because it loves you. it want to teach you how to write proper code. I just rewrote an entire project from Javascript to C#. Id rather just have learned it from the start. The results from doing it with C# talk for themself. Reduced the time for certain code snippets to less than one tenth of what they used to take. Yes, it was obv because I did something wrong when I did it with JavaScript. But C# wouldn't have any of that and forced me to do it right.

But alas, if you just wanna get ready and going for the jam I suppose JavaScript is an easier and faster way in.

Hmm, other than a stern "USE C# dammit", another tip I wish I got when I started unity is, stay away from the Array class. Use the List class instead! Yes, you can use stuffs from the .NET library even when using JavaScript. No problem. Just make sure to import System.Collections.Generic.

I am going to use unity for this, I think that is the devkit I can produce stuffs the fastest with. I will (probably) use ragepixel with it to streamline the art a bit...  I'm not 100% sure tho, it can be a bit buggy, but the benefit of drawing directly on the textures and sprites in game might just make up for that.

As a rule of thumb if you can fake the physics then do it. Although it really depends on what you're doing. If you are talking about gravity for instance you are better off coding it yourself. I've generally never had a performance issue with physics, only time I've lost frame rate was when I found that I was printing to the console 400 times a frame. In terms of feel it can be better to script it yourself primarily because you have more control over it. The First Person controller movement script in Unity is a great example of this. I really only use rigid bodies for registering collisions, raycasts, etc.
The console is extremely slow. Putting it in loops is suicide. Esp as the game and the editor is integrated and it locks up the entire thing while doing all those prints. Possibly for minutes. This also leads to one of the weak-points in Unity, debugging infinite loops, if you get stuck in one you have to force shut-down Unity. Unity don't have any way to catch slow scripts, Not even Try Catch seems to be enough for that.

Offline CaptainIcy

  • New Foal
  • *
  • Posts: 3
  • Gender: Male
  • Roll Tide.
    • Steam profile
Re: Tips for using Unity
« Reply #4 on: 2012-September 21, 00:09:49 »
I prefer Java/UnityScript, honestly. C# is fine and you are right that it is probably better overall, but I still learned Javascript and well, I want to continue using it. Never run into anything I can't do.
But yeah, some things in US turn into quite long lines, whereas in C# they're a lot shorter, I'll give it that. :P

Also yes, use Lists instead of Arrays.

I don't have too many tips really for using Unity, but I agree with most of the tips already given.

I will be using Unity for the compo. :)
Practice makes perfect. But if nobody's perfect, then why do we practice?...

Offline DuckOfDoom

  • Regular Member
  • **
  • Posts: 20
  • Gender: Male
  • (❍ᴥ❍)
Re: Tips for using Unity
« Reply #5 on: 2012-September 21, 05:23:53 »
This is now a language war. >:(

But why did you start it? :D

Offline Palm

  • New Foal
  • *
  • Posts: 4
  • Blank flank
Re: Tips for using Unity
« Reply #6 on: 2012-September 21, 10:00:25 »
This is now a language war. >:(

But why did you start it? :D
Because I started out with JavaScript. It was closer to AS3 which I worked on before, so it made sense. I really tried to do research on which language is better, just to give me a head-start. But pretty much all discussions said that they have the same capabilities and you could use any really.  But that is a lie, C# is just plain better. Yes, JavaScript can be easier to use for people with limited experience in stricter languages. And yes, you can do the same stuffs in both. But C# is better, period. And I don't want anyone to be fooled into making the same mistake as me because of the "both can do the same stuffs" rhetoric that pops up in every discussion.

Wikipedia pretty much got the syntax covered: http://en.wikipedia.org/wiki/C_Sharp_syntax

I prefer Java/UnityScript, honestly. C# is fine and you are right that it is probably better overall, but I still learned Javascript and well, I want to continue using it. Never run into anything I can't do.
But yeah, some things in US turn into quite long lines, whereas in C# they're a lot shorter, I'll give it that. :P

Also yes, use Lists instead of Arrays.

I don't have too many tips really for using Unity, but I agree with most of the tips already given.

I will be using Unity for the compo. :)
Keep doing that, not gonna stop you, not gonna say you are doing it wrong. I just to make sure that people can make an educated choice. If you are not that into coding there is probably no benefit of C# anyway. Like, there is no point having a sports car over a small-car if you ain't gonna race with it.

Offline AnsisMalins

  • Regular Member
  • **
  • Posts: 55
  • Black belt in .NET
    • LiveStream
Re: Tips for using Unity
« Reply #7 on: 2012-September 21, 11:05:07 »
Learn it right from the start and do C#. Its can be a slightly bitchier language. but it only does that because it loves you. it want to teach you how to write proper code.
MOFOKKIN TRUTH SIREN

Offline Matias

  • Hisha The Unicorn
  • Administrator
  • Regular Member
  • *****
  • Posts: 58
  • Gender: Male
  • *insert personal text here* - Later..
Re: Tips for using Unity
« Reply #8 on: 2012-September 21, 11:06:15 »
Learn it right from the start and do C#. Its can be a slightly bitchier language. but it only does that because it loves you. it want to teach you how to write proper code.
MOFOKKIN TRUTH SIREN

Please use proper English and don't do all caps. thank you :)
Heya everypony. This is a signature. /)