0
0
Unityframework~10 mins

Image and raw image components in Unity - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Image and raw image components
Add UI Canvas
Add Image or RawImage Component
Assign Sprite (Image) or Texture (RawImage)
Set Properties: Color, Size, Raycast Target
Image Displays on Screen
This flow shows how to add and configure Image or RawImage components in Unity UI to display graphics.
Execution Sample
Unity
using UnityEngine;
using UnityEngine.UI;

public class ShowImage : MonoBehaviour {
  public Image img;
  public RawImage rawImg;
  void Start() {
    img.color = Color.red;
    rawImg.texture = Texture2D.whiteTexture;
  }
}
This code sets the color of an Image component to red and assigns a white texture to a RawImage component at start.
Execution Table
StepActionComponentProperty ChangedValueEffect
1Start method calledImagecolorredImage color changes to red
2Start method calledRawImagetexturewhiteTextureRawImage shows white texture
3Frame rendersImage & RawImagedisplayupdatedBoth images appear on screen with set properties
4End---No further changes
💡 Start method finishes, images display with assigned properties
Variable Tracker
VariableStartAfter Step 1After Step 2Final
img.colordefaultredredred
rawImg.texturenullnullwhiteTexturewhiteTexture
Key Moments - 2 Insights
Why does Image use a Sprite but RawImage uses a Texture?
Image component displays Sprites which are optimized for UI, while RawImage uses Textures directly for more flexibility. See execution_table steps 1 and 2 where different properties are set.
What happens if you don't assign a Sprite or Texture?
The Image or RawImage will not display anything visible. In the execution_table, before step 1 and 2, img.color and rawImg.texture are default or null, so no image shows.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what color is the Image component after step 1?
ADefault (white)
BWhite
CRed
DTransparent
💡 Hint
Check the 'Property Changed' and 'Value' columns for step 1 in execution_table
At which step is the RawImage texture assigned?
AStep 2
BStep 1
CStep 3
DStep 4
💡 Hint
Look at the 'Action' and 'Component' columns in execution_table rows
If you remove the line 'img.color = Color.red;', what will be the Image color after step 1?
ARed
BDefault color (white)
CTransparent
DBlack
💡 Hint
Refer to variable_tracker for img.color initial value and step 1 change
Concept Snapshot
Image and RawImage components show graphics in Unity UI.
Image uses Sprites; RawImage uses Textures.
Set properties like color (Image) or texture (RawImage) to change appearance.
Add components to Canvas to display.
Without assigning Sprite/Texture, nothing shows.
Full Transcript
In Unity, to show pictures in the UI, you use Image or RawImage components. Image works with Sprites, which are special images made for UI. RawImage works with Textures, which are more general images. First, you add a Canvas to your scene. Then you add an Image or RawImage component to a UI object. You assign a Sprite to Image or a Texture to RawImage. You can also change properties like color for Image. When the game runs, these components display the images on the screen. If you don't assign a Sprite or Texture, nothing will show. The example code sets the Image color to red and the RawImage texture to a white texture when the game starts. This changes how they look on screen. The execution table shows these steps clearly, tracking changes and effects. This helps beginners see how the components update and display images.