Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Public Text UI variable not showing on inspector

Discussion in 'Scripting' started by EvenFarther, Apr 17, 2020.

  1. EvenFarther

    EvenFarther

    Joined:
    Apr 17, 2020
    Posts:
    4
    Hey I've been having problems with using the text UI features in vs, first is UnityEngine.UI not being recognized (tried fixing that with many solutions but nothing worked) so I looked for other options and moved onto using UnityEngine.UIElements and coded stuff to make it so my text on the UI can get updated depending on a unit's actions. But my public variables for the text aren't showing up on the inspector and it doesn't show an error so I have no idea why. I tried Label and Text Element. Any help? My VS version is 1.1.3 and Unity version is 2019.3.9f1

    EDIT: to be clear, only the Label and TextElement variables aren't showing up.


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UIElements;
    5. using UnityEngine.UI; //Still no idea why this doesn't work
    6.  
    7. public class ResourceManager : MonoBehaviour
    8. {
    9.  
    10.     public float gold;
    11.     public float maxGold;
    12.     public float wood;
    13.     public float maxWood;
    14.     public float population;
    15.     public float maxPopulation;
    16.  
    17.     public Label goldDisp;
    18.     public TextElement woodDisp;
    19.     public TextElement populationDisp;
    20.  
    21.     // Start is called before the first frame update
    22.     void Start()
    23.     {
    24.      
    25.     }
    26.  
    27.     // Update is called once per frame
    28.     void Update()
    29.     {
    30.         goldDisp.text = "" + gold + "/" + maxGold;
    31.  
    32.         //if(gold >= maxGold) //This makes it so that if somebody keeps collecting over max limit, it will simply be deleted and won't go any higher.
    33.         //{
    34.         //    gold = maxGold;
    35.         //}
    36.     }
    37. }
    optional: the error for the UnityEngine.UI error is "The type or namespace name 'UI' does not exist in the namespace 'UnityEngine' (are you missing an assembly reference?)
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,971
  3. EvenFarther

    EvenFarther

    Joined:
    Apr 17, 2020
    Posts:
    4
    I looked at the forum and tried the solutions and none of them worked, however I tried using unity 2017.4.28f1 and it worked. The UnityEngine.UI was now there to use. It seems that the 2019.3.9f1 version I'm using now uses .UIElement instead of .UI. I took the working 2017 version and updated it to the 2019 version and it stopped working, guess I'll need to learn UIElement now.
     
    Last edited: Apr 18, 2020