Search Unity

Unity UI Please Help! I cant seem to use any UI elements even if i use UnityEngine.UI

Discussion in 'UGUI & TextMesh Pro' started by YouBungy, Feb 19, 2020.

  1. YouBungy

    YouBungy

    Joined:
    Jun 19, 2017
    Posts:
    32
    I'm trying to use the Slider function in order to edit the value of my health bar. but for some reason, the Slider variable doesn't work and I just get errors. Heres the code
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5.  
    6. public class Healthbar : MonoBehaviour
    7. {
    8.     public Slider slider;
    9.  
    10.     public void SetMaxHealth(int health)
    11.     {
    12.         slider.maxValue = health;
    13.         slider.Value = health;
    14.     }
    15.  
    16.     public void SetHealth(int health)
    17.     {
    18.         slider.value = health;
    19.     }
    20. }
    21.  
     
  2. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,836
    What are the actual errors you are getting?

    Based on my quick skim of this documentation I don't think "maxValue" or "Value" are things that Sliders have. (Note that capitalization is important; "value" and "Value" are not the same.)
     
  3. YouBungy

    YouBungy

    Joined:
    Jun 19, 2017
    Posts:
    32
    it says that the UI component Slider doesn't exist
     
  4. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,836
    Don't paraphrase errors unless you understand what's causing them. Copy/paste the actual error message.