Search Unity

I am so confused by scripting! Please help me!

Discussion in 'Getting Started' started by Acerthorn, Dec 7, 2020.

  1. Acerthorn

    Acerthorn

    Joined:
    Jun 4, 2020
    Posts:
    15
    I want to be a game designer! I really do! And I watch the tutorials I can find on youtube about how to make a game with Unity! I really do! I really am willing to put in the effort to learn how to do this!

    But I just ... don't ... get it!

    I can add graphics to the game world. When I watch the Unity tutorials and follow along, I can place the ball graphic in the game world. I can add gravity, and even bounciness, to the ball. Hell, I can even take it a step further and add my own maze of planks, blocks, and walls in order to make that ball bounce into a specific hole! YEAH! TWO POINTS!!! WOOT!

    But then, I get to the episode where they start doing scripting (episode 4 in the playlist I provided above), and that's when it all starts going completely over my head!

    • Why does it need to be C sharp?
    • Why is this script reserved exclusively for jumping? I thought all the scripts are supposed to work with each other, in tandem, to create ONE cohesive gaming whole.
    • Why don't we need all the stuff he's getting rid of before he starts typing new stuff? if we don't need it, why does the script editor start with all that stuff enabled? What is all that stuff actually for? And how do I know I won't need it for the game I want to make?
    • What does the void update do? He doesn't delete it, and he even references it, but he never explains exactly what it does or why we need it.
    And don't even get me started when he actually starts typing new stuff! It's like he suddenly starts talking in a completely different language! What the F*** is fire1?! Why do I want it to run every frame?

    Now, let me try and understand what the whole getbutton commands mean. I think this is one of the things I kind of have a 0.0001% understanding on. Basically ... getbuttondown is like, when I press the A button in Metroid Prime on Gamecube, Samus fires a shot from her plasma beam. For getbutton, I would program Samus to charge up a charged shot with her plasma beam, and for getbuttonup, that means that, whenever I release the A button after charging a shot, the charged shot gets fired. Is that the gist of it?

    Well, what if I want to script something to happen whenever I click on it with the mouse? I can't just program something to happen whenever I press the left mouse button. I also need to do different things, depending on where on the screen I'm clicking. For example, if I'm using the mouse to navigate a menu, then clicking the left mouse button should do different things depending on which menu option I'm hovering over at the time of the click. If I'm playing a game of chess, I can't just say "left mouse click to move piece," because ... what piece?! I have to tell the game to select the piece I'm hovering over. So how do I program that input?

    But then, why a I searching for RigidBody2D? He emphasizes that I should not simply say "RigidBody," because that will cause ... problems ... but F*** me if he actually cares about us understanding this S***! And then, do I need to create the variable for jumpforce, or is it already in the unity engine by default? Also, why doesn't he add the () at the end of "addforce(jumpforce)?" He says that the () is necessary for getcomponent because that's the part that actually tells the engine to go and do the thing we just said. So why isn't it necessary for addforce?

    And then, at the very end, I notice that he can jump in middair. This isn't just a double jump. He can jump multiple times in middair. What is this, Cheetahmen from Action 52?! How am I supposed to learn how to make a game that people are actually going to want to play, when he's teaching me how to make F***ing Cheetahmen? I need to know how to script the game so that the PC only jumps when he's already standing on solid ground, so that I don't end up with Cheetahmen jump mechanics! But he doesn't tell me how to do that!

    Honestly, for a function as simple as jumping, I don't see why Unity itself couldn't just provide us with a template script that was already ready to go, where all we have to do is select what key or button will trigger this event (e.g. select the bottom face button on a gamepad), and then POOF, the script is ready to be applied to an object in the game. We can then tweak the jump height, jump length, and jump speed (while fall speed is dictated by gravity) to our liking, but the fields which modify those values should be obvious.

    For very basic, universal controls like PC movement, jumping, and attacking (either by swinging a sword or firing a projectile), why can't Unity just have preset templates for that stuff?

    Can somebody please help me out?! I am so confused!

    Is there a free to use template script for these things somewhere on the Unity asset store that I can just apply to characters?
     
    Last edited: Dec 7, 2020
  2. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    Purely because that's the only language Unity supports.
    The idea is to create modularity; good programming practice involves breaking down the overall task into multiple smaller tasks that are easier to tackle. This does not mean that script's can't work with each other in tandem, quite the opposite actually.

    To contrast, having one giant monolithic script that does everything is a nightmare to debug. Something goes wrong, and you have to sift through thousands of lines of code covering tons of different edge cases to figure out why it didn't work, and then maybe you change something that ends up breaking something else that you thought was completely unrelated in the script. In a modular setup, where each script is responsible for one specific task, if that task fails, you already know where to troubleshoot. If you want to change something later, it's also much easier to do so as well without breaking other parts of the app.

    In a nutshell, one part of the application could say "the player wants to jump now", then lets the jump script handle it.

    That's just how Unity scaffolds a new script when you create one; it adds the
    Start
    and
    Update
    methods by default because they're some of the most commonly used methods, that's all. If you don't need them for a script, then it's fine to get rid of them.

    Start is a method that is only ever called once when the script is first enabled. You can use it to setup some initial values in a script.
    Update is a method that will run once every frame. So if your application is running at 60fps for instance,
    Update
    runs 60 times per second. Generally,
    Update
    is used to handle running logic over-time, such as movement.

    My honest two cents, I don't recommend jumping right into game development without learning the core fundamentals of object-oriented programming first:
    • Classes
    • Interfaces
    • Inheritance
    • Composition
    • Polymorphism
    • Abstraction
    • Encapsulation
    Game development is based around assuming you already understand these things. If you want a general C# tutorial series unrelated to Unity, check this out:
     
  3. Acerthorn

    Acerthorn

    Joined:
    Jun 4, 2020
    Posts:
    15
    I thought Unity was specifically built so that you could make games without any coding experience.
     
  4. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    Nope. If anything, Unity is probably the one that involves the most coding out of all the free engines out there.
     
    JoeStrout likes this.
  5. Acerthorn

    Acerthorn

    Joined:
    Jun 4, 2020
    Posts:
    15
    At 2:30, the menu he's showing doesn't match what I see when I install Visual Studio Community and launch it. When I launch VSC, it looks like this: https://i.postimg.cc/02WVXVLP/A.png

    Any free-to-use engines that DON'T require programming knowledge?

    Also, why is Unity #3 on this list if it requires so much coding? https://www.nyfa.edu/student-resources/how-to-make-a-game-without-coding/
     
  6. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    Yeah, he's using VS2017 in the video, and it's UI is a little different from VS2019. If you want to get to where he starts the console app:
    • Select "Create a New Project" on the bottom-right.
    • Search for "Console App (.NET Framework)" in the search bar.
    • Select the first result in the list.
    • Give the project whatever name you want.
    • Store the project at whatever location you want on your PC.
    • Select the "Create" button.
    Nope. Some engines, like Unreal Engine (Unity has this as well) have a visual-scripting tool, where you program by connecting nodes on a graph rather than writing code, but it's not really "easier", more-so just "faster". You'd still have to apply the same programming practices, just in a different interface.
     
  7. Acerthorn

    Acerthorn

    Joined:
    Jun 4, 2020
    Posts:
    15
  8. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    I think you accidentally selected the "Continue without code" option from the first image.
    From here, just select:
    File > New > Project
    , and then its these same steps afterwards:
     
  9. Acerthorn

    Acerthorn

    Joined:
    Jun 4, 2020
    Posts:
    15
    No, I selected "Open New Project."

    This is all I get when I search for "Console App .Net Framework" https://i.postimg.cc/cCX6Bgk4/A.png
     
  10. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    Huh, I guess the modules setup shown in the video at 2:30 was skipped somehow? Not sure how that happened.

    Anyway, to fix this, you need to include the ".NET desktop development" module mentioned in the video. When you installed VSC, another application should've installed with it, the "Visual Studio Installer".
    If you search for that in your Windows search bar, it should appear. Just run that.

    Next, find your Visual Studio Community edition in the list that appears (it should be the only one in the list) and select "Modify":
    upload_2020-12-7_22-24-12.png

    Then check the ".NET desktop development" module and select "Modify" to install it:
    upload_2020-12-7_22-27-48.png

    Once that finishes installing, you should be able to see the console app project in the list when you search for it.
     
  11. Acerthorn

    Acerthorn

    Joined:
    Jun 4, 2020
    Posts:
    15
    Thank you. That seemed to get me in the front door with that guy's C# tutorial.

    It's getting late in my time zone, so I'm about to hit the hay. I'll keep watching that tutorial on and off in the coming days.

    If I run into any roadblocks, can I trust you to respond to my inquiries in a timely manner if I post them in this thread? Maybe not in a few minutes like you've been doing, but at least the same day I post here?
     
  12. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,501