Hi ArenMook,
Firstly thank you very much for developing such a nice (and easy) UI solution.
EDIT: I am clearly just retarded as I have subsequently discovered that a plain UILabel.text works perfectly fine. I could have sworn I tried it earlier only for it to not succeed, still, problem solved.
I am having a little bit of difficulty trying to work my way around creating GUI lists (think for example of a resource list in an RTS). I have been trying to create tables of prefabs comprised of labels that then get populated with the relevant information stored in corresponding containers. I am however hitting a wall because unity will not allow me to access the .mText component of the UILabel in order to change its value; it instead gives me an error message
"'UILabel.mText' is inaccessible due to its protection level."
My question then is:
a. Am I trying to do this in a round about and idiotic way that would be solved with a different approach.
b. If this is the best approach, how do I bypass this (I assume Serialization) issue that prevents me from changing the text inside of a UILabel?
Below is my Unityscript code that is iterating through my Dictionary in order to populate the Table.
#pragma strict
import System.Collections.Generic;
var lineInputPrefab : GameObject;
var parentObject : GameObject;
public enum ResourceType
{
coal = 0,
oil = 1,
wood = 2,
gold = 3,
wine = 4
}
static public var resourceDictionary
= new Dictionary
.<ResourceType,
int>();
function Start ()
{
var parentObject = GameObject.FindWithTag("resList").transform;
resourceDictionary[ResourceType.coal] = 100;
resourceDictionary[ResourceType.wood] = 200;
resourceDictionary[ResourceType.wine] = 50;
resourceDictionary[ResourceType.oil] = 465;
resourceDictionary[ResourceType.gold] = 10;
for(var value in resourceDictionary)
{
print(value);
}
}
function PopulateList ()
{
//This is currently instantiating a number of lines equal to the size of the Dictionary
for(var value in resourceDictionary)
{
Instantiate(lineInputPrefab, transform.position, transform.rotation);
print("list successfully populated");
}
var newInput = GameObject.FindGameObjectsWithTag("resInput");
//This is moving the newly created objects ("lines") to be parented under the PlayerResourceTable object.
for (var value : GameObject in newInput)
{
value.transform.parent = parentObject.transform;
var x = 0;
value.SendMessage("AddValues", resourceDictionary[x++]);
}
//This SndMsgUpWards is just re-positioning the newly created objects so that they line up.
parentObject.SendMessageUpwards("RefreshList");
}
The function that the "SendMessage("AddValues", resourceDictionary[x++]);" line is calling is below:
#pragma strict
function AddValues(dictText : String)
{
var newText : UILabel = gameObject.GetComponent(UILabel);
newText.mText = dictText;
}
It is this second script that is causing the error message.
Any help would be greatly appreciated, also to anyone responding, please keep in mind that while I am not an idiot, I am an artist/designer crossing over into programming territory, so keep it simple for me ok
