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

How can I learn to be a good programmer to write scripts? How did you learn?

Discussion in 'Scripting' started by JonnyTan, Aug 29, 2020.

  1. JonnyTan

    JonnyTan

    Joined:
    Jan 5, 2015
    Posts:
    14
    Ever since I was a kid, I have loved the thought of making my own game. I used to toy around with Javascript and C#. Now, here I am, an adult, and I plan on making a game I really want to release somewhere. A short, small, silly game, just because I really want to show off the things I can do in unity and to show I can put something together.
    Except here's the problem. I constantly spend my time trying to find ways to actually learn how to program in C# with unity and how to use everything at unity's disposal to code and put things together, such and such. But every time I look at tutorials, text, videos, etc, all I get are those "So we wanna do this, so we write this" videos and such. But they never explain why. Why I need to know what getkeydown means, where they learned it, where I could learn it, etc. What a rigid body does and how to reference it's parts in a script, etc. I can never really find tutorials or people that say hey, before getting into coding, you need to read this, watch this, know this, before I show you just what to type.
    I really want to get into this and make something with it. The scripts I do are simple but take me a really long time to figure out because I scour the internet for ways to make ends meet with them correctly. I just want to know, how did you learn to program with unity? How can I learn? What do I need to really understand from the get-go how I can work with unity in my favor and program in c# using unity's library of code? Please, any answers or help are much appreciated. I really want to learn how to code, this means the world to me.
     
  2. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    Look it up online.

    No really, I don't mean that in a condescending way or anything - a lot of programming revolves around looking up terms online.
    The Unity scripting documentation is your friend, and looking up "Unity GetKeyDown" & "Unity Rigidbody" online will bring up their documentation pages as the first results:

    https://docs.unity3d.com/ScriptReference/Input.GetKeyDown.html
    https://docs.unity3d.com/ScriptReference/Rigidbody.html
    If you're wanting to learn more about C# in general, Derek Banas has a great YouTube series where he explains everything in-depth from the very basics to the more advanced features:
    https://www.youtube.com/playlist?list=PLGLfVvz_LVvRX6xK1oi0reKci6ignjdSa

    If you're already comfortable with C# and just want to learn Unity's API specifically, try checking out their official scripting tutorial here:
    https://learn.unity.com/project/beginner-gameplay-scripting
     
  3. JonnyTan

    JonnyTan

    Joined:
    Jan 5, 2015
    Posts:
    14
    I appreciate this so much. I'm gonna try all of this. I tried looking around at the scripting documentation and I see there's a lot, do you think I should also read over all of this or slowly learn it piece by piece as I need to understand something? What worked better for you?
     
  4. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    Definitely the latter. There's a whole metric ton of information on Unity's documentation, and it's not realistic to expect anyone to read through all of it, especially since you're likely not going to use everything in the documentation in a single app.
    No point in reading through networking docs if you're only making a single player/offline game, no point in reading through iOS or Android docs if you're not planning on publishing a mobile game, etc.

    One very important thing that some new programmers often neglect is that when following tutorials, you should actually be doing them practically along side, not just read/watch them. It's easy to forget something you only read about/watched after awhile, but putting it into practice helps you retain & understand that information much more easily.
     
  5. JonnyTan

    JonnyTan

    Joined:
    Jan 5, 2015
    Posts:
    14
    Thank you so much. I am definitely gonna take your advice on this. I'll do everything I can to learn what I need. I appreciate the help so much.
     
  6. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,587
    I fully agree with @Vryken that programming is learning by doing. So instead of just reading / watching something, always use the learnt knowledge on something. This way you memorize what it's for and add it to your toolbelt, remembering about it when you are in a similar situation next time and may need a similar solution.
    I also definitely agree that it's pointless to try and read through the whole documentation. You realistically wont need most of it. When you look up a solution for a problem you are at and someone uses a feature you are not familiar with, that's when you should look it up. Ideally, next time the same feature is used you remember and dont have to look it up again (or only for details). This way you will slowly add to the tools in your toolbelt, which enables you to be flexible at approaching problems. Which is also why 'learning by doing' is so important. After all, if you have a hammer in your toolbelt but never used it, you may not realise when the right time to use a hammer has come.

    I read about the Derek Banes tutorial series being great as well. However, when i looked up some material to send to a friend who wanted to get started with Unity i ended up linking him the Sebastian Lague tutorial series on game development. He aswell starts at the very beginning, directly using Unity + C#, and offers little exercises so you can get some practical experience using your currently available knowledge. So that may be worth checking out for you too.


    After you got the basics down you will most likely be familiar with creating scripts serving as components, enabling certain behaviors for gameobjects in Unity. You will also know about methods, variables, if-statements, for-loops and some other simple programming tools. What i feel most (Unity focussed) tutorials skip over a bit much is the fact that C# is an object oriented programming language. So after feeling comfortable with the very basics i would recommend going a bit more in-depths on object oriented programming. This will give you an architectural advantage in anything but very small projects. While at it, you will also want to look into commonly used data structures. At this point you probably know about Arrays and/or Lists. However, there are specially tailored variants of those, like Queues and Stacks, which make your life easier in certain situations. It's also worth looking into Trees, and certainly worth your time to look into HashMap, which are very often one of the most efficient ways to solve some performance intense problems.
     
  7. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,336
    Only one way: the combination of reading, doing and questioning that works for you personally, all done steadily over an extended period of time. Anyone who tells you otherwise is trying to sell you something that won't work anyway.
     
    adamgolden and Suddoha like this.
  8. mgrekt

    mgrekt

    Joined:
    Jun 22, 2019
    Posts:
    92
    For me, it all began with a single class in college, not saying you have to go to college, but you need to know the basics of coding to actually understand what you're doing. It was then when I was started to progress fast, so I recommend learning the basic of the codes first.
     
  9. JonnyTan

    JonnyTan

    Joined:
    Jan 5, 2015
    Posts:
    14
    This was by far the most detailed explanation and help I've gotten, I can't thank you enough. I will definitely take all of this advice into account and go forward with this tutorial. I'm down to learn and try anything and this really means a lot to me. Thank you.
     
  10. JonnyTan

    JonnyTan

    Joined:
    Jan 5, 2015
    Posts:
    14
    I'm going to college for computer science right now but I want a bit of a jump start. Did you go to class and learn C# first, then go to unity?
     
  11. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,697
    I'm not the person you're replying to, but I also went to school for computer science, though I never touched C# in school. All of my schooling was in C and Java (with the occasional Lisp and Javascript thrown in). Java and C# are very similar though so it was pretty straightforward to add C# to my repertoire through lots of practice in personal Unity projects. Most of what I learned was on-the-job as a Java backend engineer. Programming principles are easily transferred across languages. Definitely pay attention in class! The most important thing you can learn that's unique to scripting in Unity is how the framework runs and where and when it invokes your code. This page is basically the Unity bible: https://docs.unity3d.com/Manual/ExecutionOrder.html. Once you start to really understand that diagram, all of the "magic" of the game engine melts away and it becomes just another computer program, with well defined inputs and outputs.
     
    adamgolden likes this.
  12. mgrekt

    mgrekt

    Joined:
    Jun 22, 2019
    Posts:
    92
    I touched python, coding is like very similar to each other it has mainly different rules, but overall the logic is the same. And no I actually started way before taking this college class during that time it was just to figure things out with the inspector and stuff like that.
     
    Last edited: Aug 30, 2020
  13. Modafuka

    Modafuka

    Joined:
    Nov 21, 2019
    Posts:
    45
    You should go to read ExecutionOrder.
    Learn how to Google.
    Read Unity document for those functions...
    Well, about Input.GetKeyDown(KeyCode.D) that is a straight forward sentence.
     
  14. adamgolden

    adamgolden

    Joined:
    Jun 17, 2019
    Posts:
    1,464
    The advice given is already great, @PraetorBlue Execution Order tip - that chart was also an eye-opener for me and helped dissolve a lot of mystery. As for how I learned, as a kid I was gifted a computer that didn't really come with anything. But there were these books.. where each chapter of the book had the code of a game (and we're not talking ebooks). If you typed out every line of code in the chapter without any mistakes, you could play the game! If you didn't type the chapter of code.. no game existed. There were no assets, no textures, everything was coded procedurally, in a single document, in BASIC. If I wanted to play the games, I would have to be a programmer (sort of) lol

    ..well I was also taught Logo in kindergarten - not sure if lines of stuff like FD 50, RT 90 can be considered "code" though! https://en.wikipedia.org/wiki/Logo_(programming_language)