【Unity】Introduction to game development

Meet Unity

Introduction to Unity

Unity is a cross-platform game development engine developed by Unity Technologies. It was originally launched in 2005 and quickly became one of the major engines in the game development world. Unity allows developers to write once and publish on multiple platforms, supporting Windows, Mac, Linux, iOS, Android and other platforms.

Unity is one of the most popular engines in the game industry, with a huge user base and a wide market share. According to statistics, as of 2021, more than 60% of mobile games and 30% of PC and console games are developed using the Unity engine. This number is likely to continue to grow in the future as Unity continues to update and improve its technology and adapt to the ever-changing gaming market.

In China, Unity also has extensive influence. Many Chinese game developers and companies use the Unity engine for game development. These games are not only popular in China, but also have a huge user base worldwide. At the same time, China is also an important market for Unity. Unity Technologies has branches in China and actively cooperates with the local developer community.

Unity Features

User-friendly interface : Unity provides an intuitive and easy-to-use user interface, allowing developers to quickly get started and start creating content. The editor provides a wealth of tools and functions, including scene editing, animation editing, material editing, particle systems, etc., making the development process more efficient and convenient.

Script programming : Unity allows developers to use multiple programming languages ​​such as C# and JavaScript (UnityScript) to write game logic and interactive behavior. This provides developers with the flexibility and freedom to choose the appropriate programming language according to their preferences and needs.

Asset Store : The Unity Asset Store is Unity's official asset store, where developers can buy and sell assets such as 3D models, textures, audio, plugins, and scripts. This provides convenience for developers, saves time and resources, and also promotes communication and cooperation in the community.

Cross-platform support : Unity is a cross-platform game engine that supports multiple platforms, including PC, console game consoles, mobile devices, virtual reality (VR), augmented reality (AR), and the Web. This allows developers to easily distribute games and apps to different platforms, reaching a wider audience.

Virtual Reality and Augmented Reality Support : Unity has great support for Virtual Reality (VR) and Augmented Reality (AR). Developers can use Unity to build a variety of virtual reality and augmented reality applications, providing immersive experiences and the ability to combine virtual content with the real world.

Unity case

Monument Valley : This is an acclaimed 2D puzzle game known for its gorgeous art style and unique game mechanics.

Hearthstone : A popular online card game developed by Blizzard Entertainment, which is built under the Unity engine .

Pokémon GO : An augmented reality game developed by Niantic that lets players catch virtual Pokémon in the real world.

Ori and the Blind Forest : a beautiful 2D adventure game blending a beautiful art style with an unforgettable story.

Hollow Knight : This is a popular exploration platformer praised for its beautiful 2D art style and depth of gameplay.

The Forest : This is a horror survival game where players need to survive in the wilderness and fight against hostile tribes.

Subnautica : This is an underwater survival adventure game where players explore and build bases underwater in alien worlds.

Cities: Skylines ( Cities: Skylines ): This is a city-building simulation game that allows players to create their own cities and manage their development and resources.

Sekiro: Shadows Die Twice : This is an action-adventure game developed by FromSoftware, known for its challenging combat and rich level design.

Unity installation

Go to the official website of Unity to install Unity Hub, and install the Unity LTS (long-term support version) version through Unity Hub. The path cannot contain Chinese.

Introduction to Unity Hub

Unity Hub is a desktop application launched by Unity Technologies to manage the Unity engine and projects. It is an important component of the Unity engine, designed to provide a more convenient and flexible way to install, manage and switch between different versions of the Unity engine and projects.

editor introduction

image-20230723202651251

Starting from the Unity 2019.3 version, Unity enables the Version Control System (Version Control System) by default when creating a project. This means that when creating a new project, Unity will automatically enable version control for the project, without the need to manually check the version management option. Enabling a version control system can help development teams collaborate better, track and manage changes to projects, and revert to previous versions.

Know the interface

image-20230723203557135

Scene panel (Scene) : The scene panel is the main window for editing game scenes in Unity. In the scene panel, developers can place game objects (such as characters, scene elements, etc.) into the scene, and perform operations such as position, rotation and scaling on them.

Game panel (Game) : The game panel is used to preview the running effect of the game. When the developer edits in the scene view, the game view will be updated in real time, showing the actual running effect of the current scene.

Inspector : The Inspector displays the properties and components of the currently selected game object. Developers can modify the properties of the game object in the inspection panel, and can also add, delete and adjust the components of the game object.

Project panel (Project) : The project panel displays all resource files in the project, including scene files, scripts, textures, audio, etc. Developers can manage resource files in the project view, import, create and organize resources.

Hierarchy : The Hierarchy panel shows the hierarchy of all game objects in the scene. Developers can view and manage the hierarchical relationship of game objects in the hierarchy panel, such as organizing objects into parent-child relationships.

Console panel (Console) : The console panel shows the log, warning and error messages in the Unity editor. Developers can view the information generated when the project is running in the console panel to help debug and solve problems.

Assets : The Assets folder shows the asset folder structure in the project. Developers can create, import and manage resource folders in resource folders.

Coordinate System

In Unity, a left-handed coordinate system is used.

In a left-handed coordinate system, the coordinate axes in three-dimensional space are arranged as follows:

  • X axis points to the right
  • Y axis points up
  • Z axis points forward (screen direction)

basic operation

image-20230726154030487

  • Drag scene shortcut keys: middle mouse button, Q
  • Shortcut key for moving objects: W
  • Rotate object shortcut key: E
  • Scale object shortcut keys: R, T
  • Zoom scene shortcut keys: mouse wheel, Alt+right mouse button
  • Rotate scene shortcut keys: right mouse button, Alt+left mouse button
  • Shortcut key for moving the camera: right mouse button + WASD
  • Focus object shortcut key: double-click the object in the hierarchy panel, click the object + F (in the scene)
  • Hidden object shortcut key: H
  • Switch center point shortcut key: Z
  • Shortcut key for switching coordinate system: X
  • Shortcut keys for copying objects: click on the object Ctrl+C+V, Ctrl+D
  • Delete object shortcut key: Delete
  • Undo operation shortcut key: Ctrl+Z
  • Save scene shortcut key: Ctrl+S

parent-child relationship

image-20230726155953733

A game object can only have one parent object, and a game object can have an infinite number of child objects.

  • Create a parent-child relationship

    To create a parent-child relationship, simply drag and drop one Game Object onto another Game Object, or use the Transform.SetParent() method to specify the parent in code.

  • relative position

    The child's position is relative to its parent's local coordinate system. For example, if the child's local coordinates are (1, 0, 0), then it will be one unit to the right of its parent.

  • Relative rotation and scaling

    Similar to position, the child's rotation and scaling are also relative to its parent's local coordinate system. This means that rotating or scaling a parent object affects all of its children.

  • hierarchical relationship

    Parent-child relationships can form a hierarchy, allowing you to create complex combinations of objects. An object can be the parent object of another object, and it can also be the child object of other objects, thus forming a tree structure.

  • local coordinates and world coordinates

    In the Transform component, you can access local coordinates and world coordinates. Local coordinates are coordinates relative to the parent object, while world coordinates are global coordinates relative to the scene.

  • sports succession

    When a parent object moves, all its children follow suit. This inheritance relationship can greatly simplify the associated movement between objects.

component oriented

image-20230726155811007

In Unity, "component-oriented" is a software design pattern, which is one of the core ideas of the Unity engine and the basis of Unity game development. Component-Oriented Design allows developers to build game objects by modularizing functionality into individual components, and then attaching those components to game objects, giving game objects the functionality they need.

Components are the smallest functional modules in Unity. They are an extension of the scripting class (MonoBehaviour) that can be added to GameObjects.

Each component represents a specific functionality of the game object, such as rendering, collision, movement, audio, etc.

Different components can exist on the same game object at the same time, so that the game object has multiple functions.

MaterialMaterial

In Unity, Material (Material) is an important component used to render the appearance of game objects. Materials define the color, texture, lighting properties, etc. of a game object when rendered. Using materials can make game objects display rich visual effects in the scene.

In Unity, new materials can be created by right-clicking in the Project View -> Create->Material.
You can give the material a meaningful name and set its properties in the Inspector view.

Prefab Prefab

In Unity, Prefab is an important resource type that allows developers to save game objects and their components, properties and sub-objects together as a reusable template. The role of presets in Unity is similar to "blueprints" or "templates", which can greatly improve the efficiency of creating and managing game objects.

To create a prefab, you first need to select a game object in the Hierarchy view, and then drag it into the Project view. This will create a prefab asset in the Project view that will hold all the information for the selected GameObject.

After creating the prefab, you can directly drag the prefab into the scene in the scene or in the Hierarchy view of other scenes. This will create an instance of the same GameObject in the scene as the prefab.

game script

image-20230726161018980

In Unity, game scripts are a key part for implementing game logic and functionality. Game scripts are script files written in C# or Unity's custom JavaScript (now deprecated), which can be attached to game objects to control the behavior, interaction, and animation of game objects.

  • Game Logic and Interaction

    Game scripts are used to implement logic and interactions in the game, such as character movement, enemy behavior, player input, collision detection, game rules, and more.

  • Interact with Unity components

    Game scripts can interact with game object components, such as modifying Transform components to enable movement, accessing Rigidbody components to control physical properties, and more.

  • event handling

    Game scripts can handle events in the Unity engine, such as key input, trigger collision, scene loading, etc., to implement corresponding game logic.

  • resource management

    Game scripts can also be used to load, instantiate, and manage game assets such as models, materials, textures, sounds, and more.

  • animation control

    The game script can control the animation of the game object by operating the Animator component, so as to realize the character action and transition effect.
    Components to control physical properties etc.

  • event handling

    Game scripts can handle events in the Unity engine, such as key input, trigger collision, scene loading, etc., to implement corresponding game logic.

  • resource management

    Game scripts can also be used to load, instantiate, and manage game assets such as models, materials, textures, sounds, and more.

  • animation control

    The game script can control the animation of the game object by operating the Animator component, so as to realize the character action and transition effect.

Guess you like

Origin blog.csdn.net/m0_51942776/article/details/131942950