- Home /
This question was
closed Jul 30, 2021 at 01:18 PM by
loafy123.
Question by
loafy123 · Apr 16, 2020 at 10:58 AM ·
c#unity 2dvisual studio
Slider will dissapear after reaching a value
hello, Im new to Unity. I want to make the slider dissapear then another UI image pop up when the slider reach a certain value. For example maybe my max value is 5 and I want to slider to dissappear when value of 5 is reached. Normally I would use SetActive for item to dissappear but it seems like it doesnt work for UI.
Comment
Answer by exp626stitch · Dec 17, 2020 at 09:19 PM
@loafy123 Try:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ChangeUI : MonoBehaviour
{
public Slider slider; //set this to your slider
public GameObject otherUiElement; //set this to your other element
public void Start()
{
otherUiElement.SetActive(false);
}
public void Update()
{
if(slider.value <= 0)
{
slider.gameobject.SetActive(false);
otherUiElement.SetActive(true);
}
}
}
I would also like to point out that
slider.SetActive(false);
Wouldnt work but
slider.gameObject.SetActive(false);
does.