How to Get Started With Game Development Using Unity

What Is Unity?

Why Is Unity So Popular?

  • Affordable Cost: Anyone can get started with Unity via its free version. And for veteran developers who are looking for extra features, affordable monthly plans do the trick.
  • Less Code Dependency: Unity is beginner-friendly and does not require much prior coding knowledge. In fact, it is possible to create a game from scratch without even writing a single line of code.
  • Strong Community Support: Unity sports a friendly community environment where developers can always reach out for and receive prompt help.
  • Graphic Suite: With a rich library of high-quality visual effects and high customization, Unity supports the development of intuitive games with smooth and natural movements and rendering.

Unity For Beginners — Your First Project

1. Editor Window

  • Hierarchy: Nests and structures all the GameObjects that are being used in a scene.
  • Scene View: Caters to the placement and movement of various GameObjects.
  • Inspector: Shows all available details of GameObjects that are present in the scene.
  • Game View: Gives a preview of the player’s point of view while playing the game.
  • Assets / Project: Stores details and components such as textures, models, scripts, etc.

2. Elements of Unity 3D

  • Assets: They are the representation of an external file (audio, image, texture) that can be imported in Unity. Assets can include animation files, renders of textures, audio mixers, and more.
  • Project: A location that holds all the files in your current project along with their assets.
  • Packages: A cluster of game assets that have been precompiled and included in Unity.
  • GameObject: All possible objects that are used in a game are called GameObjects. They function as placeholders for important components such as Transform, Light, or Script.
  • Components: Basic building blocks of games that include the details of all objects in a game and their activities.
  • Scenes: Scenes act as the base on which GameObjects are placed to make Levels. Multiple Levels are then put together and linked to create game sections.
  • Prefab: Reusable GameObject components that can be used on multiple scenes by creating ‘Instances’.
  • Build: An export of the game that contains all scenes for playbacks.

3. Built-in Components

  • MeshRender: Assigns materials to a 3D Mesh.
  • Light: Illuminates a scene or parts of it.
  • [Box | Mesh] Collider: Used during collisions to enable detection of GameObjects.
  • Camera: Attaches the Player viewport to a GameObject.
  • MeshFilter: Assign different materials to a 3D mesh to a GameObject.
  • Rigidbody: Acts on GameObjects with 3d Meshes by using realistic physics simulation.
  • Multiple UI Canvas Components to display GUIs.

4. Adding and Managing Assets

  • Add the image to Unity by dragging and dropping it to ‘Assets’.
  • Now drag this file onto the Scene section to add it to the current scene.
  • You may now notice the ‘Transform’ properties of this object on the right-hand panel. Here you can edit the Position, Rotation, and Scale factors to see and understand how it behaves.
  • Once done, click on the Play button to see that the image is now a part of the game and visible.

5. Engine Physics Components

6. How to Add C# Script

  • Right-click in the Assets panel. Navigate to CreateC# Script
  • You will now see a new file under Assets called NewBehaviourScript.
  • Rename the script to your choice. For example, while defining the position of the object, you can name the script as Position (for easy retrieval). Since we will be defining the movement of our player ball here, let’s name it as Movement.
  • Start() method: Run by the script when the GameObject is initialized and becomes active. It is used to set the initial state of GameObjects, such as the bullets in a gun as depicted in the example below:
    public int bullets;
  • Update() method: Called once per frame, this is where all the action of games takes place including the addition of forces, detecting user input, spawning, etc.

7. Rigidbodies

  • Navigate to the inspector for the GameObject and click on AddComponent.
  • As soon as you click on this, you will notice the ball fall out of the scene. This is because of the Gravity Scale property of Rigidbody. Setting it to 0 will solve this.

8. Movement of Game Objects

  • ballBody.velocity = is used to assign a velocity to the Rigidbody that is denoted by ballBody.
  • Vector2 defines the velocity of the Rigidbody with input parameters in x and y axes.
  • Input.GetAxisRaw("Horizontal") and Input.GetAxisRaw("Vertical")are used to handle inputs corresponding to the Horizontal and Vertical input axes based on the movement buttons that the player is pressing (up, right, down, left).
  • speed defines the speed with which the object will move in the direction of movement.

9. Accepting User Inputs

  • Input.GetKey(KeyCode.W) Returns True when the player holds down the W key.
  • Input.GetKeyDown(KeyCode.W) Returns True when the player first presses the W key.

Conclusion

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Xccelerate

Xccelerate

Advancing technology by bridging the talent gap. Based in Hong Kong.