- Home /
Question by
Conqueror1 · May 03, 2020 at 12:43 AM ·
uisliderlevelprogress-barmax
Once the slider has reached maximum value: set Level Complete UI (Active)
Hello, I am currently making a game where you collect items and it fills a progress bar. Unfortunately, I cannot seem to figure out a script that sets my Level Complete UI canvas to "Active" when the Progress bar is = to max value. Assistance would be greatly appreciated.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ProgressBar : MonoBehaviour
{
public Slider slider;
public GameObject LevelCompleteUI;
public void SetMaxProgress (int progress)
{
slider.maxValue = progress;
slider.value = progress;
}
public void SetProgress (int progress)
{
slider.value = progress;
}
}
Comment
public void SetProgress (int progress)
{
slider.value = progress;
if(slider.value>=maxProgress){
LevelCompleteUI.SetActive(true);
}
}
Best Answer
Answer by Conqueror1 · May 05, 2020 at 05:28 PM
Thank you! :) <3 I had modified the code a bit since me posting it. Your suggestion worked! Here is the code for everyone following this question. Remember to assign everything in the Inspector.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ProgressBar : MonoBehaviour
{
public Slider ProgressSlider;
public GameObject LevelCompleteUI;
public void SetMaxProgress (int progress)
{
ProgressSlider.maxValue = progress;
ProgressSlider.value = progress;
}
public void SetProgress (int progress)
{
ProgressSlider.value = progress;
if (ProgressSlider.value >= ProgressSlider.maxValue)
{
LevelCompleteUI.SetActive(true);
}
}
}
Your answer
Follow this Question
Related Questions
How to create a gradient progress bar 3 Answers
4.6 UI "Slider" jumps on handle press? 2 Answers
Gradient issue with slider 1 Answer
Better way of making a 4.6UI slider to return even values only 1 Answer