[Video][Game Making Tutorial 2] Creating a Character + Coding Basics

 

Here are some further explanations to tie in with the Unity2D Starter Tutorial Video, here are the Assets used in that tutorial. You can also go to the Forum to post any doubts about it.

  • Sprite: A Sprite is any graphic you choose to import to your 2D game. It’s just a “drawing” if nothing else is done to it.

 

  • Sprite Importing: To import sprites to your game, you just have to drag and drop it into the Assets folder in Unity. The inspector will show several options.
    • Settings:
      1. Sprite Mode: Set it to Multiple.
      2. Pixels per Unit: This number represents how many pixels there are in a point. Your game must have a constant Pixel per Unit to look better. We’re going to set it to default, which is 100.
      3. Go into the Sprite Editor. In here, to the top left, there’s a button that states Slice. Click there and it’s going to be “Automatic” by default. This way your sprites will separate by themselves. You can also fix the sprites by drawing your own boxes for each one of them.
      4. Filter Mode: Since this game is a Pixel game (meaning the art is really smallish), we’re going to choose Point from the options (this means there’s almost no postprocessing).
      5. Max Size: Should be more than the file’s size, it defines the size of the same file IN UNITY. I’m using 512.
      6. Format: TrueColor for the colors not to be processed.
Sprite Sheet

Sprite Sheet Example

  • SpriteRenderer: This Component contains information about a Sprite. You can recolor sprites, change sprites and more. If this doesn’t exist, your object will be invisible in the Scene.

 

  • Rigidbody2D is the way your “Sprite” becomes interactable. This element adds a “body” to anything in the Scene. You can move rigidbodies and interact with them through code. To do this:
    • Create a Scripts Folder in the Assets Area.
    • In there, create a C# Script just like this:
    • Now, in the Script, go to the Variables Area. (Described in the bottom of this post).
    • There, name your Rigidbody2D to anything you want. Just type RigidBody2D Name; . Never forget the semicolon.
    • Now in the Start Method, Initialize your variable. Do that by typing in the name of your Rigidbody and “Getting” it. Like this:
      1. Name = GetComponent<RigidBody2D>();
    • And by doing that, now when you say Name anywhere else, Unity will know you’re talking about the rigidbody and you can play around with its properties or move it around. You can see more of that in the video.

 

  • BoxCollider2D: This Component adds collision detection to any object. It’ll be the boundaries of any object to come into contact with another. If you have a box and don’t have a collider, the box will be untouched by any other objects. As soon as you add it, you’ll see the magic. You can also set Colliders to be Triggers, which means they’re not affected by collisions but they can “feel” those collisions.

 

  • Vector2: Vector2s are components that store 2 numbers within them. These numbers are set as X and Y.

 

  • Mathf: This function works for Mathematic operations. For example, if you want to know the Sign of a number, you’d do Mathf.Sign(xxx) The xxx is your number of course. Mathf.Abs(xxx) makes your number “Absolute” which in math terms means it’s always positive. There’s many more, and we’ll be covering them later.

 

 

Coding EXTREME Basics

For coding, I need to teach you several very basic things. Just keep these tips in mind and we’ll learn pretty fast:

  • After EVERY line of code, you need a semicolon ( ; ). If you don’t have it, your code won’t work.
  • Variables are just numbers, words or switches. Numbers can be Floats (any number is a float), Integers (Int in code, these are full numbers like 1,2,3,4), Doubles (Decimal numbers like 1.4). Words are called “Strings”. Switches (True or False) are called Booleans or Bool in code.
  • You must declare your variables in the Variable Area.
  • VARIABLE AREA
  • To declare variables, you have to plan what you need. When you figure out what you need, you need to decide if it’s Public (do you want other scripts to read this?), standard (doesn’t matter) or Private (do you want other scripts to absolutely NOT read this?). After that, you write:
    • public int phonenumber; declares an integer phonenumber.
    • float speed; declares a float called speed.
  • Variables can also be Components, as I said up there. For example, RigidBody2D. In this situation, you’d type:
    • RigidBody2D rigid; declares a RigidBody2D called rigid
  • After having your variables declared, you have to initialize them. For this, you write inside the Start Method. Aka:
    • Void Start(){ YOUR CODE GOES HERE}
  • start
  • To initialize them, you must write a value that will be the starting value of the variable. For Numbers you can leave it empty if you’re going to set it up in the inspector. But for Booleans and Components, you must declare them. For example:
    • Variable Area: bool test; — Start() { test = true ;} is all you need to do for Bools
    • Variable Area: RigidBody2D rigid; —- Start() { rigid = GetComponent<RigidBody2D>(); }
  • Getting a Component is the only way to play around with it. You can also get components from other objects but we’ll get to that later.
  • Anything preceded by // becomes a comment and doesn’t affect your code in any way.

 

Feel free to ask anything about this, you can go to the Forums if you’d like more information and help from the userbase.

 

Share

Leave a Reply

Your email address will not be published. Required fields are marked *