Search Unity

Scripting Help (Noobest of Noobs)

Discussion in 'Getting Started' started by williamsmd90, Sep 23, 2018.

  1. williamsmd90

    williamsmd90

    Joined:
    Sep 3, 2018
    Posts:
    22
    I'm stuck. I just don't know where to go. I started with learning some basics of C#, I've done some 3D tutorials, and now I'm reading through the documentation. Basically, none of that is really teaching me much. I can't figure out how to get context for a lot of the things I feel like I should be learning from anything I do.

    The tutorials on the learn section helped the most, but they're still pretty limited. Even those are outdated and I had to Google how to fix all the problems I came across. A friend suggested I look through the documentation, but I have no idea how some of those things are even used. For example, I've been reading the FindGameObjectsWithTag section and I have no clue what it's meant to do. I figure I can ask on the forums, but I feel guilty asking for help with what I assume are simple topics. I was reluctant to even post this.

    I guess I'd like to find a source with more comprehensive information to really familiarize myself with the countless functionalities and figure out how they're used in a practical sense. Or to get suggestions for people who've taught themselves Unity.

    P.S. Apologies if I'm posting in the wrong section. The Answers section is down.
     
    DerrickMoore and JoeStrout like this.
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    OK, first, welcome to Unity! Don't be shy about asking questions. That's what this forum is for.

    The tutorials are the best place to learn. Yes, some of them are outdated; you can either download the older version of Unity they were written for, or google for how to update the scripts (which might be even more educational if you can manage it). They still do the best job of giving you the context you seek. As soon as you see a tutorial that has a need to find a game object by its tag, you'll understand what FindGameObjectsWithTag is useful for. If you never see such a tutorial, then you won't have wasted your time learning something you don't need (I know I pretty much never use this method in my own games).

    So, work through the tutorials. When you reach the end of one, try to take it a little farther: add a new type of enemy, or a new ability the player can do, or add a high-score list, or whatever catches your fancy. You will probably run into something you don't know how to do; if googling it doesn't turn up the info you need, then ask for help here.

    Just reading through the docs from front to back is probably not helpful — this is especially true of the scripting reference. The Manual is better; you might read one section of that over lunch each day or something like that, so at least you have a big picture of what Unity's capabilities are. But mostly you will retain stuff better if you read it when you need it.

    Be patient with yourself. Programming is a skill, like playing the violin; you can learn the basics in a few months, but you will never reach a point where you can't get any better. It's also incredibly fun and rewarding. So enjoy the journey, and remember, those of us who have walked this path before are always happy to show newbies the way.
     
  3. williamsmd90

    williamsmd90

    Joined:
    Sep 3, 2018
    Posts:
    22
    I really appreciate this! Thanks for the advice and motivation. It helps more than I can say.
     
    Tset_Tsyung and JoeStrout like this.
  4. Tset_Tsyung

    Tset_Tsyung

    Joined:
    Jan 12, 2016
    Posts:
    411
    Hi Williamsd90,

    Cannot say enough how true what joe is saying (to be fair, joe pretty much hits the nail on the head all the time...). You've clearly started off corectly by doing the 'Learn' section tutorials. I don't know how many of them you've done (or if this has been said already) but do as many of them as you can. Even if it's not the genre you're interested in you will always learn something.

    In answer to youre question about FindObjectWithTags, there's 2 Topic Sections (found below the project tutorials in the learn section) that may be of interest.

    Interface & Essentials
    https://unity3d.com/learn/tutorials/topics/interface-essentials
    In here, under the heading "Essential Unity Concepts" there are a few videos on GameObjects and Tags. Hopefully this will help shed some light on that method you were unsure about (of course, it's now wednesday and you probably sorted it by now, lol)

    Scripting
    https://unity3d.com/learn/tutorials/s/scripting
    If there's something within the main C# language that you're unsure of you may find an answer about it here.

    But, as joe said, you're always welcome to post a clear question here.

    Right... I need coffee... welcome to Unity and the forums. Look forward to hearing from you soon.

    Mike
     
    JoeStrout likes this.
  5. BoogieD

    BoogieD

    Joined:
    Jun 8, 2016
    Posts:
    236
    It's all hard to understand at first but it will start making sense bit by bit if you keep at it. The learning never stops though.

    FindGameObjectsWithTag. If you look at the top of the Inspector you will see a field called 'tag' which you can use an existing one or define a new one. If you had spawning zombie characters among other characters in the game you could give all the zombies the tag 'zombie'.
    Then when you wish to do something to all the zombies like making them dance you could get them by using: FindGameObjectsWithTag("zombie"). It will return an array filled with all the characters with the tag zombie. Then it is just a matter of going through the array using a 'for' loop to make each one start dancing with animation etc.

    A few beginner tips:
    # Defining a 'public' variable in a script makes it visible in the script Inspector. This is where you can alter parameters for your code from the interface rather than inside the script itself.
    # If you need to get access to say a GameObject in the scene from your script, make a public GameObject variable and drag the required GameObject into that field in the Inspector. Now the variable has the GameObject assigned to it so you can access it with your script code.
    # If you want to get to other scripts or components like perhaps a rigidBody from a script use GetComponent.

    I hope this helps make it not so daunting.
     
    Last edited: Sep 26, 2018
    DerrickMoore and Tset_Tsyung like this.