Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Complete C# (sharp) beginner - Any tips on learning?

Discussion in 'Scripting' started by Batzarro, Apr 27, 2012.

  1. Batzarro

    Batzarro

    Joined:
    Apr 22, 2012
    Posts:
    51
    Sorry about this post being unbelievably general.

    I'm currently reading 'Unity 3.x Game Development Essentials' by Will Goldstone. It's real good and all, but I've tried to learning programming and scripting in the past, and I'm still getting stuck. I can copy the scripts from the book and they'll work, but I find that I still don't really understand what's going on. I read the descriptions, but like in other books I've read, they seem to assume you have some prior knowledge of "coding" in general. For example;

    "Functions or methods as they are also known, most often start with the term void in C#. This is the function's return type, which is the kind of data a function may result in. As most functions are simply there to carry out instructions rather than return information, often you will see void at the beginning of their declaration, which simply means that a certain type of data will not be returned."

    I know this is early in the book, and I can just continue on after it with little effect, but to be honest I don't totally understand it. I'm posting this because I think that if I don't totally understand everything this early on, later when it get's more complicated, I will just get lost, and also never actually memorise anything I can use later. I mean, saying something like a void is also known as a function or method is just confusing to me. And "This is the function's return type", returning from where to what? What, how, when...

    Scripting in C#, or scripting in general, is very abstract to me. In short, I'm a dumbass, and I was wondering if there's any kinds of miraculous visual guides out there that could help me? I mean, the bit in the book that says stuff about;

    Dog.breed;
    Dog.fetchStick(25);

    That analogy kinda stuff did help a little, but still, I need pictures and stuff, or something. Or am I talking nonsense? Should I just keep going on and it will just start to all fall into place?

    Thanks for your time.
     
  2. diablo

    diablo

    Joined:
    Jan 3, 2011
    Posts:
    736
    Yeah, that book is cool for teach Unity basics, but not for teaching programming. For programming, you need something like C# for Dummies, but keep in mind that programming isn't for everyone, and it requires you to sit down and really read and think hard and do the actual problems.
     
  3. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    Ew - never buy a for Dummies book. :)

    The WRox Professional series of books on C# and .NET are hugely informative IMHO.
     
  4. diablo

    diablo

    Joined:
    Jan 3, 2011
    Posts:
    736
    I suggested the Dummies book as a last resort; from the reviews on amazon, it would seem to work more for the layman while the Wrox books are generally for people already in the field.
     
  5. dom_g

    dom_g

    Joined:
    Apr 29, 2009
    Posts:
    54
    Programming is complicated and simple at the same time. Best way start is to mess about with logic without concerning yourself too much about fancy bits. First important thing to learn about are variables, they hold information that you will use throughout a game/piece of software, next thing functions, how to take those bits of data - numbers, strings, arrays and to create something out of them. Start really simply, 1 scene just creating random strings / numbers from set data maybe.No 3D models / graphics, simply scripts doing things. Use the debug.log a lot, and learn how to check on what is happening within the program.

    I started with UnityScript, with a bit of prior knowledge about programming, two years ago. Now I program in Objective-C for job and coming back to Unity with C#. I'd say stick with C#, the logic will be the same no matter what language you use - although in Unity the Editor features make it different from using theoretical objects.

    Programming at first is abstract. The more you read and more importantly try to program, the more it will sink in. I never used to return data when I created my two games with unity - it wasn't that obvious to me and I used workarounds anyway. The more you immerse yourself the more you'll get out of it.

    For instance with your example:

    Dog.breed

    Dog can be a class / blueprint for a dog type so you might have created a lot of Dog objects that share the same property - breed.

    In a game context, it could be simply checking what sort of Dog it is. So you can create a way of deciding about it.

    if (Dog.breed == alsation){
    Log(@"its pretty big");
    }

    if (Dog.breed == chihuaha){
    Log(@"its really small");
    }

    Programming is like making decisions and thinking about if a certain condition meets a requirement to make another decision.
     
  6. meth0s_

    meth0s_

    Joined:
    Dec 11, 2011
    Posts:
    60
    To be honest when i first started doing small app's i used xerox.net very simple tuts for cpp from there i went on to doing 2 courses 1 in interactive gaming and the other bs in computer science then from there worked as a intermediate programmer then got made redundant lol. so now im working for my self ( broke looking for work ). i recommend a course to teach you the fundamentals and basics that you will need to get a head in your career if this is truly your passion and what you want to do.
     
  7. Batzarro

    Batzarro

    Joined:
    Apr 22, 2012
    Posts:
    51
    Thanks to all of you for your advice! If anyone else has something to say though, feel free to reply. I don't want to sound like I'm fine now and closing the topic.

    Thanks dom_g, I read your mssg, and I will read it again tomorrow, when I can understand it better (it's half midnight for me now).
     
  8. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
  9. blurededge

    blurededge

    Joined:
    Mar 14, 2012
    Posts:
    255
    As it happens, I'm going through the same book, though I'm a bit further on (a bit better than half way through at this point). My first piece of advice, would be not to sweat it too much if you don't understand everything yet. In the early part of the book, while you're going through the prototype phase, things aren't as well explained for a novice as they might be. This concerned me as well, as I'm a complete C# noob myself. A bit further on, the explanations get more in depth and are generally easier to follow. Also, just by virtue of writing some of the scripts, you'll become more familiar with C# syntax and structure, which also tends to make things easier.

    As far as the specific passage you posted, the best way to think about it for me is this: There are two very important building blocks to writing code (there are more than two, but these two are probably the most fundamental). Variables, and functions. A variable is made up of two parts, a data type, such as "Int" for integer, "float" for floating point (any number that has a decimal in it), or "GameObject" which would be, well, a 3d object in the game. So the first part of the variable just tells Unity what type of data this variable should contain. The second part is the name of the variable. The name is completely arbitrary, and is up to you what you want to call it. However, it's a good idea to use some standard conventions as it makes the names and how you spelled/capitalized them easier to remember. Once you "declare" a variable (basically just write it's two parts, the data type and a name you give it) it is then usable within your script. So a complete variable might be

    GameObject newEnemy;

    or

    float bombTimer;

    Variables can have an initial value set for them when declare them or not, that's up to you and weather it suits the purposes of your script to do so. So if we declared an initial value for the second variable example, you might use:

    float bombTimer = 3.0f;

    In this case we've set the initial value of the "bombTimer" variable to 3.0.

    Functions usually make use of variables to actually do things. They might return a certain data type (such as our examples above), which might be used for something somewhere else in the script, or more frequently they just carry out sets of instructions. In the case where they're just carrying out instructions rather than returning data, they would start with "void," as they have no data type that needs to be returned.

    Hope this helped, if you want we can PM so we don't irritate the real programmers on the board with our complete noob discussion. Going through the same book at the same time might be helpful to both of us.

    Cheers!
     
    TJanc likes this.
  10. blurededge

    blurededge

    Joined:
    Mar 14, 2012
    Posts:
    255
  11. JRavey

    JRavey

    Joined:
    May 12, 2009
    Posts:
    2,377
    I'm going to go against the grain. You will never become a good C# programmer if you think of it as a Unity tool, you might be good at C# as it applies to Unity, but you'll probably overlook a ton of great things you can do in and out of Unity.

    Learn Unity, but on a parallel track, play around with raw C# and learn what you can do. There is much you can do to extend Unity, but if you only know what Unity can do, how could you extend it?
     
  12. blurededge

    blurededge

    Joined:
    Mar 14, 2012
    Posts:
    255
    Sound advice JRavey. I'm working through this book for the time being. After this, I'll be doing one of two things. Time, and registration permitting, I'll take the C# course at the local CC when the fall semester starts. It's offered as an online course usually, so that should work around my schedule. If I can't get the course, I'll pick up the Head First C# book and use that. Always been part of the plan for me, because your right, just learning C# within the context of Unity is unnecessarily narrow.
     
  13. BrynP

    BrynP

    Joined:
    Mar 7, 2012
    Posts:
    49
    I found 3D Buzz's Hyperion tutorial a fantastic way of getting into C#. Although it's in the 'XNA' section, it only uses C# and the .NET framework. At the end you'll have a complete text adventure that runes from the console and you will have learned a lot about how to use C# (because the 3D Buzz guys are really good at putting things into context and making them clear and understandable even for a complete beginner) and of course you'll have 'game design' on the brain. Then 3D Buzz has some really useful Unity3D tutorials and their scripting ones all use C#.

    Maybe watch 3D Buzz tutorials in this order:
    Hyperion C#
    Unity3D 3rd Person Character Controller
    Unity3D 3rd Person Platformer

    This is all I used to get started.
     
    TJanc likes this.
  14. blurededge

    blurededge

    Joined:
    Mar 14, 2012
    Posts:
    255
    Thanks for the tips! I'll check those out. And I have game design on the brain anyway.

    Cheers!
     
  15. Zethariel1

    Zethariel1

    Joined:
    Mar 21, 2012
    Posts:
    439
    The simplest thing you can do is google the terms that you do not understand -- something like method + c#. You are bound to find definitions that suit your way of understanding material :)
     
  16. Ted-Chirvasiu

    Ted-Chirvasiu

    Joined:
    Sep 7, 2010
    Posts:
    381
    TJanc likes this.
  17. Batzarro

    Batzarro

    Joined:
    Apr 22, 2012
    Posts:
    51
    Good stuff. Thanks for all the advice, you lot. I have a lot more of that book to get through.