0
0
Unityframework~20 mins

Materials and textures in Unity - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Master of Materials and Textures
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Unity C# code when applying a texture?

Consider the following Unity C# script snippet that assigns a texture to a material. What will be the color of the material's main texture pixel at (0,0) after this code runs?

Unity
Texture2D tex = new Texture2D(2, 2);
tex.SetPixel(0, 0, Color.red);
tex.SetPixel(1, 0, Color.green);
tex.SetPixel(0, 1, Color.blue);
tex.SetPixel(1, 1, Color.white);
tex.Apply();

Material mat = new Material(Shader.Find("Standard"));
mat.mainTexture = tex;

Color pixelColor = ((Texture2D)mat.mainTexture).GetPixel(0, 0);
Debug.Log(pixelColor);
ARGBA(1.000, 0.000, 0.000, 1.000)
BRGBA(0.000, 0.000, 1.000, 1.000)
CRGBA(0.000, 1.000, 0.000, 1.000)
DRGBA(1.000, 1.000, 1.000, 1.000)
Attempts:
2 left
💡 Hint

Remember that SetPixel sets the color at the specified coordinates before Apply() updates the texture.

🧠 Conceptual
intermediate
1:30remaining
Which Unity shader property controls the smoothness of a material?

In Unity's Standard Shader, which property name is used to control how smooth or shiny a material appears?

A"_Emission"
B"_Metallic"
C"_BumpMap"
D"_Glossiness"
Attempts:
2 left
💡 Hint

Think about the term that relates to surface reflection sharpness.

🔧 Debug
advanced
2:30remaining
Why does this texture not appear on the material in Unity?

Look at this code snippet. The texture is created and assigned to the material, but the object remains untextured in the scene. What is the most likely cause?

Unity
Texture2D tex = new Texture2D(128, 128);
// Forgot to call tex.Apply()
for (int y = 0; y < 128; y++) {
    for (int x = 0; x < 128; x++) {
        tex.SetPixel(x, y, Color.yellow);
    }
}
Material mat = new Material(Shader.Find("Standard"));
mat.mainTexture = tex;
AThe material was not assigned to any renderer component.
BThe texture size is too large and causes a memory overflow.
CThe texture was never applied with tex.Apply(), so changes are not updated.
DThe shader "Standard" does not support textures.
Attempts:
2 left
💡 Hint

Remember that Texture2D changes require a specific method call to update.

📝 Syntax
advanced
2:00remaining
Which option correctly creates a tiled texture offset in Unity C#?

You want to tile a texture twice in both X and Y directions and offset it by 0.5 on X axis. Which code snippet correctly sets this on a material?

A
mat.mainTextureScale = new Vector2(2, 2);
mat.mainTextureOffset = new Vector2(0.5f, 0);
B
mat.SetTextureScale("_MainTex", new Vector2(2, 2));
mat.SetTextureOffset("_MainTex", new Vector2(0.5f, 0));
C
mat.mainTextureScale = new Vector2(0.5f, 0);
mat.mainTextureOffset = new Vector2(2, 2);
D
mat.SetTextureScale("_MainTex", new Vector2(0.5f, 0));
mat.SetTextureOffset("_MainTex", new Vector2(2, 2));
Attempts:
2 left
💡 Hint

Remember that mainTextureScale and mainTextureOffset are properties, but SetTextureScale and SetTextureOffset require the texture property name.

🚀 Application
expert
3:00remaining
How many unique colors will this procedural texture contain?

This Unity C# code creates a 4x4 texture where each pixel color depends on its coordinates. How many unique colors does the resulting texture have?

Unity
Texture2D tex = new Texture2D(4, 4);
for (int y = 0; y < 4; y++) {
    for (int x = 0; x < 4; x++) {
        Color c = (x == y) ? Color.black : Color.white;
        tex.SetPixel(x, y, c);
    }
}
tex.Apply();
A2
B4
C8
D16
Attempts:
2 left
💡 Hint

Think about how many pixels are black and how many are white.