How to approach C#?

This might’ve been asked before, so I apologize if somebody else did(I searched but couldn’t find a concrete answer to what I am looking for). I am fairly new to programming language(the only programming I know if PHP). I have followed a couple of tutorials and have a grasp of the basics, like syntax and such, but I wanna get the language down, so that I can come up with my own code. What I want to know, is how should I go about learning C#? The reason I am asking is because I don’t know how Unity uses C#, meaning, I’m not sure how and what functions are used. Any help is greatly appreciate it =]

Cheers

Very carefully and with a baseball bat.

These are a few good books that I have read and reviewed on the subject and would not hesitate to recommend to programmers who are unfamiliar with C# but are already reasonably accomplished at a couple of other languages:
C# In A Nutshell http://www.amazon.com/C-4-0-Nutshell-Definitive-Reference/dp/0596800959
Pro C# and .NET 4.0 platform
http://www.amazon.com/2010-NET-Platform-Andrew-Troelsen/dp/1430225491/ref=pd_sim_b_2/188-0364516-4260247
Programming C# 4.0 http://www.amazon.com/Programming-4-0-Building-Applications-Framework/dp/0596159838/ref=pd_sim_b_5/188-0364516-4260247

They aren’t specifically Unity related, but they will give you a good grounding in C# and .NET and it is really .NET that you want to learn the most about and will require the most knowledge acquisition as C# the language is reasonably small.

Even though the books cover C# and .NET 4.0 and Unity’s version of Mono is 3.5, many of the principles are still the same, and Unity will eventually upgrade to support the .NET 4.0 features.

Hope that helps a little bit.

lol figures, I suck at searching properly >.<

C# In a nutshell seems really good. Question, how is .NET related to C#? the only .NET I am familiar with is ASP.NET =[

Btw thanx a bunch for the reply, and not flaming even tho this was asked or posted before =]

Whilst .NET is a framework upon which the languages of C#, F#, VB.NET, IronPython, etc are built and execute, you can think of .NET as the library of functions that you call from those other languages. Unity then adds their own functionality and function calls that are specific to their application that sit on top of .NET also. Mono is the Open Source implementation of .NET and are almost, but not quite, equivalent to each other.

C# in a nutshell is certainly a good first book to start with. Very clearly written and concise.

Ah I see, makes sense then. So .NET is like the foundation for each language. I always thought of .NET as ASP.NET and nothing more. I learned something new today, thanx for the insight.

I don’t know if this will help you or not, but two years ago I couldn’t write a “hello world” program in C# and today I’m doing it professionally as a developer. After only a month of working in C# I developed my first application (a mobile barcode scanning software used for inventory at my company). How did I manage that?

While I would love to claim that I read a lot of books, I didn’t. I would love to tell you that I spent those two months in a class room, but that wouldn’t be true either.

In the end, I download Visual Studio Express and simply started. The trick really was to surround myself with as much visual input (video Tutorials) as possible, starting small with infamous programs like Hello World and cotinue to simply invent more and more elaborate projects until I got to the point where I was actually making useful stuff. Working in a team with other programers was also a really important thing, because as I learned to make things work, people where constantly showing me the flaws in structure, code or what not. AKA showing me better ways to do things. When I started working with Unity I really had a strong understanding of at least how C# worked and when I started the newbie tutorials here they simply made perfect sense.

The morale of the story is the best way to learn is to simply start and if you are going to learn C# while creating Unity programs, while not the best way to do it, as long as you are programming and really trying very hard to keep things as simple as bloody possible you will very rappidly pick things up as long as your enthusiasm for it doesn’t waver, because it really just takes time for things to sink in.

My suggestion is to find guys like me, who are just a little bit ahead of you and get together with them and work with them on projects. At first you probobly won’t be able to contribute too much, but just having access to someone who is actively working on things and having conversations, looking at code, watching tutorials… all that stuff at once, a few hours each day. It won’t take you more than a few weeks before someone asks you, hey can you create a little interface for this thing for me and you know exactly what to do and how to do it.

But I will repeat myself and say… start small. Tiny… Im talking trying to create a C# script that lets you move a box around in a 2d enviroment. Than try to add a ball that bounces of it. Try to create a counter of how many times you can bounce that ball of it. Anytime you get stuck… do some Youtube tutorials (Tornado Twins are awsome).

Oh and really try not to post questions until you are really really stuck. Really try to work through problems. Force yourself to try to figuire things out, because everytime someone feeds you a line of code, while you can solve the problem, it teaches you the bad habbit of not relying on yourself. That was a really tough lesson for me. But building up the confidence to do it yourself and get through problem yourself is really a big part of the process.

Im starting to get a little winded, but I couldnt help but notice how much your post reminded me of me when I got started. Its a great journey and Unity3d is an awsome experiance. I have search high and wide for various tools, languages, engines out there and I can tell you that for beginners there really is no substitute for Unity3d. It is simply the most ideal learning enviroment you could possibly ask for.

Woah that is a long post lol

I have been following a couple of tutorials on C# and made some working scripts out of them. The thing is that in some of them I just basically “copy/paste” the code and try to figure out what is what, and sometimes I just get stuck scratching my head. For this reason, I want to start studying the basic of C# and studying it rather than just copy/pasting code. I will follow ur advice tho, on working on simple scripts and practice with the small bit of C# knowledge I have, and then as I study work on more complex stuff. I will do my best not to ask questions frequently, unless I lose patience with the bit I get stuck on XD. I usually never give up on something I take interest in, no matter how hard it is(which reminds me of the time I started studying PHP lol).

I did a small game in Unity using the Tornado Twins(shamless plugging >.<):

The thing with that, is that this is done using JavaScript(or UnityScript as they call it). Seeing as this seems less complex to me( especially cuz it is very similar to ActionScript, which I have studied before), I wanna go for C#.

Unity3D is indeed fun and I always have fun in the learning process of a new program I like. BTW, I appreciate you sharing your thoughts =]

You know copying code and looking at code examples, trying to figuire out what they do and such is actually a very good way to learn. I mean you aren’t going to be creating final products ready for release as you are learning the tool, so you don’t have to bother with things like copyrights, credits and such. Rip it apart, if someone posts their code its more often than not by design posted to be a learning tool.

Just make sure you don’t get into the habit of copy/paste/use and move on kind of training. You want to understand at least the basic concept and reasons behind how different code works.

Another important thing too is, don’t re-invent the wheel. Even as you learn, you want to progress with your games and see them function in some way. Sometimes you take some code and know what it does, but nescessarly how and thats fine, you won’t always understand everything and hell often times it so happens that I write some code and a few months later I look at my own code and don’t remember exactly what the hell its doing. That’s just kind of part of the learning process.

Key to the whole thing is to just programmer all the bloody time. You would be suprised how much you can learn in a 3 hour focused session and even when you get stuck and you search for answers you’ll find yourself running across different ways of looking at things. It all kind of comes together in the end.

I forgot those Tornado tutorials where in Java, when I did them I simply translated everything to C#. In any case, 3d buzz has a great tutorial for a 2d shooter done in C#, that is a really great start to finish project with a focus on the absolute bottom level basics. Definitly be sure to do that one.

I spent my time going through Head First C#, It was a really good book. The author guides you through the process of programming in C# and introduces topics fairly quickly. There are a LOT of example projects, and you end up making about 3 games as part of the projects for the book. Personally I went through it because I haven’t done any computer programming in years since I last used C++/C. It helped me get a good grounding for Unity :slight_smile: Something to note, when you go through one of these books, make sure to do all of the practice examples! You learn by doing, especially when it comes to programming!

Once I’ve finished my first two game projects that I’m working on, I plan on going back and learning more C#. I don’t think you can ever stop learning, gotta keep practicing and reading!

dude, i was never a programmer, but what really helped me was these main things,

its all logic, it taps into unity, and you controll it. First get familiar with c#, i suggest reading a book, getting a friend to teach you, or simply watching videos. Then get familiar with unity and the unity reference, which can be found in mono developes “Help” click on the “unity API reference”. Main things to remember
Variables are types that are being used to define an action, object, or number. This can have to do with the objects mobility, speed, look, or even texture. First make varialbes based on what you need, for instance i want to make an object move. I would make a variable that has to do with it like, how fast: pubilc float speed = 20; how far: private transform myDistance,

then you need to learn how to put those into action.

void start(){} / this does it automatically when the script starts running
void Update(){}/ this allows the script to change when a certain variable, statement, or function has been called.

ill do mine on update.

so it would probably look like this

void Update(){

if(Input.GetKeyDown(KeyCode.F)){

myDistance.postion = new vector3(10,0,0);

}

}

it seriously takes a wake up call to get it but once you do its like magic