Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


SpriteRenderer

A component that renders a Sprite. If a GameObject has a SpriteRenderer component, the component renders the assigned Sprite asset on the screen using the position, rotation and scale from the Transform component. You can use this to draw characters, items, backgrounds, and other visual elements in a 2D game.
Read time 10 minutesLast updated 2 days ago

Definition

[RequireComponent(typeof(Transform))]public sealed class SpriteRenderer : Renderer

Remarks

Examples

using UnityEngine;// This example script demonstrates how to change the sprite and the sprite color, and flip the sprite horizontally and vertically.// Attach this script to a GameObject with a SpriteRenderer component and assign a Sprite to the Sprite field in the Inspector.public class Example : MonoBehaviour{ public Sprite sprite; private SpriteRenderer m_spriteRenderer; private void Awake() { // Fetch the SpriteRenderer from the GameObject m_spriteRenderer = GetComponent<SpriteRenderer>(); } private void Start() { // Change the sprite to the one in the sprite field m_spriteRenderer.sprite = sprite; // Change the color of the sprite to red m_spriteRenderer.color = Color.red; // Flip the sprite horizontally m_spriteRenderer.flipX = true; // Flip the sprite vertically m_spriteRenderer.flipY = true; }}

Properties

Property

Description

adaptiveModeThresholdThe current threshold for Sprite Renderer tiling.
colorRendering color for the Sprite graphic.
drawModeThe current draw mode of the Sprite Renderer.
flipXFlips the sprite on the X axis.
flipYFlips the sprite on the Y axis.
maskInteractionSpecifies how the sprite interacts with the masks.
sizeProperty to set or get the size to render when the SpriteRenderer.drawMode is set to SpriteDrawMode.Sliced or SpriteDrawMode.Tiled.
spriteThe Sprite to render.
spriteSortPointDetermines the position of the Sprite used for sorting the SpriteRenderer.
tileModeThe current tile mode of the Sprite Renderer.

Methods

Method

Description

GetBlendShapeWeightGets the weight of a blend shape for this renderer.
RegisterSpriteChangeCallbackRegisters a callback to receive a notification when the SpriteRenderer's Sprite reference changes.
SetBlendShapeWeightSets the weight of a blend shape for this renderer.
UnregisterSpriteChangeCallbackRemoves a callback (that receives a notification when the Sprite reference changes) that was previously registered to a SpriteRenderer.

Inheritance

Inherited Members

Operators

Operator

Description

operator ==Compares two object references to see if they refer to the same object.
boolDetermines whether the object exists.
operator !=Compares if two objects refer to a different object.