Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a Slider variable in Unity.
Unity
public [1] healthSlider; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using int or float instead of Slider type.
Using GameObject which is not specific to sliders.
✗ Incorrect
In Unity, to use a slider UI element, you declare a variable of type Slider.
2fill in blank
mediumComplete the code to set the slider's value to 50.
Unity
healthSlider.[1] = 50f;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting maxValue instead of value.
Trying to set minValue to change current slider position.
✗ Incorrect
The value property sets the current position of the slider.
3fill in blank
hardFix the error in the code to update the slider's value smoothly.
Unity
healthSlider.value = Mathf.[1](healthSlider.value + Time.deltaTime, 0, maxHealth);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Lerp which does not restrict values.
Using Max or Min which only compare two values.
✗ Incorrect
Mathf.Clamp keeps the value between the minimum and maximum limits.
4fill in blank
hardFill both blanks to create a progress bar that updates based on current and max health.
Unity
healthSlider.[1] = (float)currentHealth / [2];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting minValue instead of value.
Dividing by minValue or using enabled property.
✗ Incorrect
The slider's value should be set to the fraction of current health over max health.
5fill in blank
hardFill all three blanks to initialize a slider's min, max, and current value properly.
Unity
healthSlider.[1] = 0f; healthSlider.[2] = maxHealth; healthSlider.[3] = currentHealth;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up minValue and maxValue.
Setting enabled instead of value.
✗ Incorrect
Set minValue to 0, maxValue to maxHealth, and value to currentHealth to initialize the slider correctly.