Hello to all of you, It may be a silly subject, but I've been searching a lot without finding a real answer. I would like to disable a slider but it doesn't work. Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class Enemy : MonoBehaviour { public Slider HealthBar; void Start () { HealthBar.enabled = false; }
Or if you want to disable the slider script and not the gameobject : Code (csharp): slider.GetComponent<Slider>().enabled = false;
Just to be clear because all these are subtly different: SetActive(false) operates on the game object and will make it and all it's children disappear. scrips on these objects will no longer receive Update() invocations somecomponent.enabled = false will cause Unity to no longer call Update() on that script if the parent object is active; all other methods remain invokable someUIcomponent.isinteractable = false ONLY works on UI elements that descend from UI.selectable (e.g. a slider) and will cause it to be unresponsive to clicks, and be drawn accordingly. -ch