Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a Sprite variable in Unity.
Unity
public [1] mySprite; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Texture instead of Sprite
Using GameObject for sprite variable
✗ Incorrect
The Sprite type is used to hold sprite assets in Unity.
2fill in blank
mediumComplete the code to load a sprite named 'hero' from the Resources folder.
Unity
mySprite = Resources.Load<[1]>("hero");
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Texture2D instead of Sprite
Using GameObject which loads prefabs
✗ Incorrect
Use Resources.Load<Sprite> to load a sprite asset by name.
3fill in blank
hardFix the error in the code to assign a sprite to a SpriteRenderer component.
Unity
GetComponent<SpriteRenderer>().[1] = mySprite; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using texture instead of sprite
Using image which is for UI components
✗ Incorrect
The sprite property of SpriteRenderer sets the displayed sprite.
4fill in blank
hardFill both blanks to create a sprite from a texture and assign it to a SpriteRenderer.
Unity
Texture2D tex = Resources.Load<Texture2D>("icon"); Sprite spr = Sprite.Create(tex, new Rect(0, 0, tex.[1], tex.[2]), new Vector2(0.5f, 0.5f));
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using size or length which are not Texture2D properties
✗ Incorrect
Use width and height properties of Texture2D to define the sprite rectangle.
5fill in blank
hardFill all three blanks to load a sprite, assign it to SpriteRenderer, and set its color to red.
Unity
SpriteRenderer sr = GetComponent<SpriteRenderer>(); sr.[1] = Resources.Load<[2]>("enemy"); sr.[3] = Color.red;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using material instead of color
Loading as Texture2D instead of Sprite
✗ Incorrect
Assign the loaded sprite to sprite property, load as Sprite, and set color property.