TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

Unity 2D

Unity 2D with Introduction, Installing, GameObject, First Unity Project, Unity 2D, Sprite Unity, Loops, If Statement, Data Types, Swith Statements, Unity UI, Unity Asset Store etc.

<< Back to UNITY

Introduction to Unity 2D

Unity is available for both 2D and 3D games. When you create a new project in Unity, you will have a choice to start in 2D or 3D mode. The choice between starting from 2D or 3D mode determines some settings for the Unity Editor, such as whether images are imported as sprites or textures. You can swap between 2D or 3D mode at any time regardless of the mode you set when you created your project.

Sprites in Unity

Sprites are simple 2D graphic objects that have graphical images (called textures) on them. Unity handles sprites by default when the engine is in 2D mode.

If you are 3D, sprites are essentially just standard textures, but there are special techniques for combining and managing sprite textures for efficiency and convenience during development. When you view the sprite in 3D space, sprites will appear to be paper-thin, because they have no Z-width.

Sprites always face the camera at a right angle unless rotated in 3D space.

When you create a new sprite, it uses a texture. This texture is then applied on a fresh GameObject, and the Sprite Renderer component is attached to it. This makes our GameObject visible with our texture, as well as its properties related to how it looks on-screen.

Creating Sprites

To create a sprite to your game, you must supply the engine with a texture. Let's create a texture first.

  • Get an image what you want to add as a sprite in standard image file such as PNG or JPG that you want to use,
  • Save it in your system directory and
  • Then drag the image into the Assets region of Unity.
Unity 2D
  • Now drag the image from the Assets into the Scene Hierarchy.

You will notice that as soon as you let go of the mouse button, a new GameObject with the name of the texture shows up in the list. You will also get the image now in the middle of the scene in the scene view.

Unity 2D

Let us consider the following points while adding a sprite:

  • By dragging from an external source into Unity, we are putting an asset.
  • This added asset is an image, so it becomes a texture.
  • By dragging this texture into the scene hierarchy, we are creating a new GameObject with the same name as our texture, with a sprite renderer attached.
  • This sprite renderer uses that texture draws the image in the game.

We have now added a sprite in our scene.

Sprite Modes

This setting is used to specify how the sprite graphic is extracted from the image. To choose the modes, click on a sprite in the Assets/ Sprites folder, in the inspector, there are three different modes in which you can use Sprites:

Unity 2D

Single: It is used for a single image sprite.

Multiple: It is used for a sprite with multiple elements, such as animations or spritesheets, with different parts for a character.

Polygon: It is used for a custom polygon-shaped sprite that you can create many different types of primitive shapes with, for example, Square, Triangle, Pentagon, Hexagon, etc.

Modifying Sprites

We can manipulate the imported sprites in various ways to change how it looks.

If you look at the top left corner of the unity interface, you will get a toolbar, as shown below:

Unity 2D

Let's see the functions of these buttons:

A first-Hand tool is used to move around the scene without affecting any objects.

Unity 2D

The next tool is the Move tool. This is used to move the objects in the game world around.

Unity 2D

The next tool is the Rotate tool, which is used to rotate objects along the Z-axis of the game world or parent object.

Unity 2D

The centered tool is the Scale tool. This tool allows you to modify the size (scale) of the objects along certain axes.

Unity 2D

The next tool is the Rect tool. This tool behaves like a combination of the Move and the Scaling tool but is prone to loss of accuracy. It is more useful in arranging the UI elements.

Unity 2D

The next tool is the Move, Rotate, and a Scale tool. It is used to move, rotate, and scale the selected object.

Unity 2D

And finally, the last tool is the Custom Editor tool.

Unity 2D

These tools are very useful and worthy as the complexity of the project increases.


Next Topic2D Sprite Sheet




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf