Consider this Unity C# script snippet that changes a material's color in the Start() method. What color will the material have after running?
using UnityEngine; public class ColorChanger : MonoBehaviour { void Start() { Renderer rend = GetComponent<Renderer>(); rend.material.color = Color.red; rend.material.color = new Color(0, 1, 0, 1); // green } }
Think about the order of color assignments.
The material color is first set to red, then immediately changed to green. The last assignment determines the final color.
This Unity C# code tries to read a float property from a material. What will it print?
using UnityEngine; public class PropertyReader : MonoBehaviour { public Material mat; void Start() { if (mat.HasProperty("_Glossiness")) { float gloss = mat.GetFloat("_Glossiness"); Debug.Log(gloss); } else { Debug.Log("Property not found"); } } }
Check if the material has the property before reading it.
If the material has the property "_Glossiness", it prints its float value. Otherwise, it prints "Property not found".
This Unity C# script tries to change the color of a material but the color does not update in the game. Why?
using UnityEngine;
public class ColorFail : MonoBehaviour {
public Material mat;
void Start() {
mat.color = Color.blue;
}
}Think about how Unity handles shared materials vs instances.
Changing a shared material affects all objects using it but may not update the renderer's instance color. To change color per object, use renderer.material.color instead.
Choose the correct Unity C# code to set a texture named "_MainTex" on a material.
Check the method signature and property name case sensitivity.
The method SetTexture takes the property name as the first argument and the texture as the second. The property name is case sensitive and must include the underscore.
You want to make a material's emission color fade from black to red smoothly over 3 seconds in Unity. Which code snippet achieves this?
Think about using a coroutine and Color.Lerp with elapsed time.
Option D uses a coroutine to interpolate the emission color smoothly over 3 seconds from black to red. Other options either do not interpolate correctly or reverse the colors.