Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Learning to script in Unity using C#

Discussion in 'Scripting' started by Deleted User, Feb 20, 2015.

  1. Deleted User

    Deleted User

    Guest

    Hi, I have a simple question to you guys who know how to script...

    My main issue is learning C# scripting in Unity... most tutorials just ask you to copy what they do without teaching what you are actually doing. When I start new projects on my own, I'm lost and don't know how to start with the scripting. I bought many tutorials and books and still I feel like I'm not getting enough out of it. Maybe my approach is wrong, I don't know.

    Can anyone give me some tips or advice to learn how to script?
    How have you guys learned it?


    Any help would be greatly appreciated, Thanks.
    - Yuriy.
     
  2. Glockenbeat

    Glockenbeat

    Joined:
    Apr 24, 2012
    Posts:
    669
    Use the Unity tutorials, most of them are in C# and always make use of a goal and tell you what you are actually doing.
    http://unity3d.com/learn

    Pretty good stuff for starters!
     
  3. cmcpasserby

    cmcpasserby

    Joined:
    Jul 18, 2014
    Posts:
    315
    Always have a goal in mind to directly apply the skills you are learning too, make use for the unity docs and the msdn. For beginner stuff there are some great tuturials in the learn section, that can take you all the way from first learning to code to having a simple game completed.

    I really have to stress my first point about having a goal to apply the skills you learn too, since if you don't you wont be able effectively commit this new knowledge to memory.
     
  4. reinfeldx

    reinfeldx

    Joined:
    Nov 23, 2013
    Posts:
    162
    Good advice so far. I learned to script using Unity. Three tips from me:

    I started learning to script using the Lynda.com tutorial here: http://www.lynda.com/Unity-2D-tutorials/Unity-2D-Essential-Training/159243-2.html. There could be better options out there, but I liked this one as it focused on 2D. I think this website requires a paid subscription but I got a free membership through my university.

    You must watch this video. Consider watching the next two in the series as well. http://unity3d.com/learn/tutorials/...first-game/how-to-start-your-game-development

    Finally, it is my opinion that there are no shortcuts to learning how to script and only consistent effort will get you there. And the more effort the better!

    Good luck!
     
  5. Deleted User

    Deleted User

    Guest

    Thank you for all the advice, I will definitely try and utilize all of your tips.

    I was wondering if I needed to learn C# Programming first before learning it within Unity but after watching some C# in Unity tuts I think it's not necessary.
     
  6. reinfeldx

    reinfeldx

    Joined:
    Nov 23, 2013
    Posts:
    162
    In my experience, working with Unity is a good way to learn, so no need to become a C# master before getting started. That said, there is definitely no harm in looking at other non-Unity C# references/tutorials along the way!
     
  7. gtzpower

    gtzpower

    Joined:
    Jan 23, 2011
    Posts:
    318
    I learned C# first, but that's just because I have been programming for many years prior to using Unity. If you are completely new to programming, I would actually suggest going through some beginner C# tutorials to learn the language itself first, or possibly even a book.

    But that is my opinion. However you feel like doing it is what you should do. The most effective method of learning is the one you "want" to do :)
     
    reinfeldx likes this.
  8. QuinnWinters

    QuinnWinters

    Joined:
    Dec 31, 2013
    Posts:
    490
    Some may disagree with me on this piece of advice, but I recommend you not spend any more money learning how to code. I've been coding for over 15 years in a multitude of languages and I've never spent a dime. The internet can teach you all you need to know for free.

    Start small. Think up some small goal you want to accomplish, such as making a cube or ball move around, and use the internet to learn how to do it. Start combining the small things you've learned to make more complex things. Then do something a little more complex, and then a little more complex. Google is the ultimate tool for learning to code. When you can't find an example of how to do something (and hopefully a bit of explanation along with the example) that's what places like this are great for.

    All coding/scripting is, is a bunch of small little things working together to make larger more complex things.
     
  9. bloomingdedalus

    bloomingdedalus

    Joined:
    Aug 13, 2012
    Posts:
    139
    Everything in Unity made much more sense after I downloaded Visual Studio Express, spent six months creating various programming that had nothing to do with Unity and then came back to Unity. That's how I learned C#... I have tens of thousands of lines of code in Visual studio doing everything from creating normal maps to creating pseudo-file systems to advanced encryption to various control modules for Windows Forms....
     
  10. bloomingdedalus

    bloomingdedalus

    Joined:
    Aug 13, 2012
    Posts:
    139
    I agree that the programming books I've bought mostly just sit on my Kindle doing nothing...

    This book is essential, in my view, if you want to be working in 3-space programming: http://www.amazon.com/Advanced-Engineering-Mathematics-Publishers-Mathematics/dp/0763779660

    Everyone should have that book - it's the best math reference book I've ever seen...
     
  11. reinfeldx

    reinfeldx

    Joined:
    Nov 23, 2013
    Posts:
    162
    As good an approach as any, but I personally would burn out well before the six month mark if I were programming file systems, encryption, and control modules. Traditional programming exercises just don't appeal to me. I agree with gtzpower's point above about learning by programming whatever he/she wants to program.

    Good tip on the book. Will check it out.
     
  12. ddulshan

    ddulshan

    Joined:
    Mar 16, 2014
    Posts:
    190
    I used to learn through very basic Videos, Official Videos and other in Youtube. I suggest you go to JavaScripting, it's real easy for beginners and when you get the hang of it, you can easily switch to C# or continue Java. Both languages follow the same Principles though the usage is a bit different.

    Here, the official tuts, start from the very beginning. http://unity3d.com/learn/tutorials/modules/beginner/scripting
     
  13. bloomingdedalus

    bloomingdedalus

    Joined:
    Aug 13, 2012
    Posts:
    139
    I disagree - I don't think Java is any easier than C# - I originally pretty much did start in Java and I don't see how it's any easier other than being able to cast things are "var" - but honestly that's just a bad habit that you'll have to unlearn later - so there's no point in doing it... C# is as easy as Java - I don't believe anyone who says otherwise as I did start learning in Java and then realized almost all tutorials for Unity were in C# so I switched. It took like two weeks to adapt to the syntax, not bad, but I see nothing about Java that makes it easier to start with.
     
  14. bloomingdedalus

    bloomingdedalus

    Joined:
    Aug 13, 2012
    Posts:
    139
    Fair enough, for me the things I made I enjoyed making - I made them because I enjoyed programming them. I wasn't reading exercises out of anything. I think that I missed out a lot on learning the power of .NET and C# in general by confining myself to Unity when I started coding - which is why I recommended trying to learn it out of Unity. There's simply things about the language you're far less likely to find implemented in Unity tutorials and guides. Like, for example, multithreading - you'll probably find few to no tutorials about building multithreading into Unity as you can't access anything from Unity from other threads - but if you have any intensive calculations/data processing you need to do in the background, there's no reason to limit yourself to a single processor core. A lot of the things I built in Visual studio I built as supplimentary classes with the idea of incorporating them into unity - for example, a 3d perlin noise generator that generates seamless textures on spheres for planet texture generation, a height map to normal map converter, coordinate structures that go beyond the capacity of floating point precision in Unity's coordinates, etc. Don't limit yourself to thinking that everything you could want to do in C# for Unity is best done within monodevelop. A lot of great game components can be easily developed with Visual Studio which has a far superior and easier to use debugger than Mono's.

    But, yes, I agree, if you're not enjoying what you're programming, you're probably not going to learn much. But I also believe you're not going to learn as much from limiting yourself to learning to code in MonoDevelop.

    For example, this week I built a voxel mesh engine in a few days. The total code in Unity is about 30 lines. There's ~2000 lines for it I wrote in Visual Studio that don't interact with the UnityEngine namespace at all. I have eight threads hammering away in the background building voxel chunks. It takes a selection of coordinates from a Unity script, samples the areas with the selected settings, puts it into a queue where eight threads take their turns sampling millions of perlin samples, building meshes, and building the final mesh arrays, and then it drops them in a thread safe dictionary I wrote which Unity checks every frame for updates. When there's a new chunk ready, all the Unity thread does is grab the final mesh arrays and assign them to the mesh filter. If the Unity thread were processing all the stuff the background threads were doing, there would be a major frame rate drop because it's a fair amount of processing to do 16,000,000 3d Perlin samples and build a 256x256x256 voxel mesh...

    Of course, I like RPG like games - which means that the game engine is just a GUI for some fun math games....
     
    Last edited: Feb 21, 2015
  15. cmcpasserby

    cmcpasserby

    Joined:
    Jul 18, 2014
    Posts:
    315
    JavaScript != Java
     
  16. ddulshan

    ddulshan

    Joined:
    Mar 16, 2014
    Posts:
    190
    else JavaScript == UnityScript;
    Lol

    Yeah. But I told about "Beginners". Who don't know a bit about things. Even the "var" will make things easy. But as you know the beginning part of C# scripts, and also the Mono class thing which need be as the same as the file name. For a beginner it's hard and not familiar of those things TBH I started with JS because of the same problem! The file name of the C# code was different from the name in the code. I wasted days to figure it out!

    And like I said I "suggest", you can choose any you want and think is easy and familiar to you.
     
  17. cmcpasserby

    cmcpasserby

    Joined:
    Jul 18, 2014
    Posts:
    315
    else JavaScript != UnityScript
    If you ever worked with real js is is completely different from what unity calls JavaScript
     
  18. cmcpasserby

    cmcpasserby

    Joined:
    Jul 18, 2014
    Posts:
    315
    I think much of the problem here is that it is hard for experienced programmers to understand what is easier for a complete noob. Since I leaned C# with unity and found it easy but I also came to C# and unity with years or C++, Java and Python experience as well as experience with other games engines like ue3 and source
     
  19. image28

    image28

    Joined:
    Jul 17, 2013
    Posts:
    457