Divide a spriteA 2D graphic objects. If you are used to working in 3D, Sprites are essentially just standard textures but there are special techniques for combining and managing sprite textures for efficiency and convenience during development. More info
See in Glossary into nine sections so Unity can stretch or repeat the different sections, and add a collisionA collision occurs when the physics engine detects that the colliders of two GameObjects make contact or overlap, when at least one has a Rigidbody component and is in motion. More info
See in Glossary shape.
Follow these steps:
Select the sprite texture in the Project window.
In the InspectorA Unity window that displays information about the currently selected GameObject, asset or project settings, allowing you to inspect and edit the values. More info
See in Glossary window, set MeshThe main graphics primitive of Unity. Meshes make up a large part of your 3D worlds. Unity supports triangulated or Quadrangulated polygon meshes. Nurbs, Nurms, Subdiv surfaces must be converted to polygons. More info
See in Glossary Type to Full Rect, then select Apply.
If you set Mesh Type to Tight instead, 9-slicing might not work correctly, because of the way Unity generates and renders the sprite.
Select Open Sprite Editor.
Select the sprite you want to 9-slice.
Click and drag the green handles inward to define the borders of the sprite, for example the walls of a floor tile. Or enter the values in the Sprite overlay, using the L, R, T, and B fields for left, right, top, and bottom.
The borders define the nine areas of the sprite: the central area (E), the four walls (B, D, F, and H), and the four corners (A, C, G, and I).
Select Apply.
Drag the sprite asset from the Project window to the SceneA Scene contains the environments and menus of your game. Think of each unique Scene file as a unique level. In each Scene, you place your environments, obstacles, and decorations, essentially designing and building your game in pieces. More info
See in Glossary view as normal.
In the Inspector window for the sprite, in the Sprite RendererA component that lets you display images as Sprites for use in both 2D and 3D scenes. More info
See in Glossary component, set Draw Mode to Sliced or Tiled depending on the behavior you want. For more information, refer to 9-slicing modes.
Note: Setting Draw Mode to Sliced or Tiled means the Sprite Renderer component controls the ColliderAn invisible shape that is used to handle physical collisions for an object. A collider doesn’t need to be exactly the same shape as the object’s mesh - a rough approximation is often more efficient and indistinguishable in gameplay. More info
See in Glossary 2D component. As a result, you can’t edit the Collider 2D component manually.
When you resize this sprite, the sections behave as follows:
If you set Draw Mode to Sliced, Unity uses simple scaling if you resize the sprite using the Transform component of the GameObjectThe fundamental object in Unity scenes, which can represent characters, props, scenery, cameras, waypoints, and more. A GameObject’s functionality is defined by the Components attached to it. More info
See in Glossary or the transform tool in the Scene viewAn interactive view into the world you are creating. You use the Scene View to select and position scenery, characters, cameras, lights, and all other types of Game Object. More info
See in Glossary.
If you set Draw Mode to Tiled, use the Tile Mode property to control how Unity repeats, or tiles, the texture. The options are:
A value of 1 for Stretch Value means the sprite repeats when the sprite is twice its original size. A lower value means the sprite repeats less often.
To add a collision shape to a 9-sliced sprite, follow these steps:
Select the sprite in the Hierarchy window.
In the Inspector window, select Add Component.
Select either a Box Collider 2D or Polygon Collider 2D component.
Other types of Collider 2D component don’t support 9-slicing.
Enable Auto Tiling. Unity now automatically updates the collider shape when the dimensions of the sprite change.
Unity can add additional edges to the collider shape when you enable Auto Tiling. This can have an effect on collisions.