0
0
Unityframework~10 mins

Material properties 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 set the color of a material to red.

Unity
Material mat = GetComponent<Renderer>().material;
mat.color = [1];
Drag options to blanks, or click blank then click option'
AColor.yellow
BColor.blue
CColor.green
DColor.red
Attempts:
3 left
💡 Hint
Common Mistakes
Using a color name that is not predefined like 'Red' instead of 'Color.red'.
Forgetting to access the material from the Renderer component.
2fill in blank
medium

Complete the code to change the metallic property of a material to 0.5.

Unity
Material mat = GetComponent<Renderer>().material;
mat.SetFloat("[1]", 0.5f);
Drag options to blanks, or click blank then click option'
A"_BumpScale"
B"_Glossiness"
C"_Metallic"
D"_EmissionColor"
Attempts:
3 left
💡 Hint
Common Mistakes
Using "_Glossiness" which controls smoothness, not metallic.
Using property names that do not exist in the shader.
3fill in blank
hard

Fix the error in the code to correctly set the emission color of a material.

Unity
Material mat = GetComponent<Renderer>().material;
mat.[1];
Drag options to blanks, or click blank then click option'
ASetColor("_EmissionColor", Color.green)
Bcolor
CSetColor("_Emission", Color.green)
DemissionColor
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to set emissionColor property directly which does not exist.
Using wrong property name like "_Emission".
4fill in blank
hard

Fill both blanks to create a dictionary of material names and their smoothness values for materials with smoothness greater than 0.5.

Unity
var smoothMaterials = new Dictionary<string, float> {
    { [1], mat.GetFloat([2]) }
};
Drag options to blanks, or click blank then click option'
Amat.name
B"_Smoothness"
C"_Glossiness"
D"mat.GetName()"
Attempts:
3 left
💡 Hint
Common Mistakes
Using "_Smoothness" which is not the correct property name.
Trying to call a non-existent method mat.GetName().
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase material names to their emission colors if emission intensity is greater than 0.

Unity
var emissionDict = new Dictionary<string, Color> {
    { [1], mat.GetColor([2]) }
    where mat.GetFloat([3]) > 0
};
Drag options to blanks, or click blank then click option'
Amat.name.ToUpper()
B"_EmissionColor"
C"_EmissionIntensity"
Dmat.color
Attempts:
3 left
💡 Hint
Common Mistakes
Using mat.color instead of mat.GetColor("_EmissionColor").
Checking emission with wrong property name.