0
0
Unityframework~10 mins

Sprite Renderer component in Unity - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to get the Sprite Renderer component from the GameObject.

Unity
SpriteRenderer spriteRenderer = gameObject.GetComponent<[1]>();
Drag options to blanks, or click blank then click option'
AComponent
BRenderer
CSprite
DSpriteRenderer
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Renderer' instead of 'SpriteRenderer' returns a different component.
Using 'Sprite' is incorrect because it's not a component.
Using 'Component' is too general and won't get the sprite renderer.
2fill in blank
medium

Complete the code to change the sprite color to red.

Unity
spriteRenderer.color = [1];
Drag options to blanks, or click blank then click option'
AColor.red
BColor.green
CColor.white
DColor.blue
Attempts:
3 left
💡 Hint
Common Mistakes
Using a color other than red when the instruction asks for red.
Trying to assign a string instead of a Color object.
3fill in blank
hard

Fix the error in the code to enable the Sprite Renderer component.

Unity
spriteRenderer.[1] = true;
Drag options to blanks, or click blank then click option'
Aactive
Bvisible
Cenabled
Dshow
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'visible' which is not a property of SpriteRenderer.
Using 'active' which is a GameObject property, not component.
4fill in blank
hard

Fill both blanks to set the sprite and flip it horizontally.

Unity
spriteRenderer.sprite = [1];
spriteRenderer.[2] = true;
Drag options to blanks, or click blank then click option'
AnewSprite
BflipX
CflipY
DoldSprite
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'flipY' instead of 'flipX' flips vertically, not horizontally.
Assigning 'oldSprite' instead of the new sprite.
5fill in blank
hard

Fill all three blanks to create a dictionary mapping sprite names to their colors if the color is not white.

Unity
var spriteColors = new Dictionary<string, Color>()
{
    { [1], [2] }
};

if (spriteColors[[3]] != Color.white)
{
    Debug.Log("Color is not white.");
}
Drag options to blanks, or click blank then click option'
A"heroSprite"
BspriteRenderer.color
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names without quotes for dictionary keys.
Using incorrect keys when accessing the dictionary.