Hey all, just a quickie.
i have a score collector that 'collects' through out each level scores, achievements etc.
it is stored until the last scene were the GUI will display all this;
my questions is how do i make my labels or text display and do math functions, like... you see: "5 power ups X 100 points = 500"
var Collector: GameObject;
function Start () {
Collector = GameObject.Find("Collector");
}
And on the function OnGui i'd like to do this;
GUI.Label (Rect (10, 10, 100, 20), "Tackled '+tackledamount' X DO MULTIPLY by 100 = "answer" ");
... yeh that looks terrible.. but i want it to end up on screen as;
"Tackled X times 100 points = X"
... and the values i want to grab from the script "Collector"... so i dont know how to take those value and use them in this GUI script or how to do the math on them on the gui?
Matty
thanks for your help, i didnt know the syntax to use, so thank you for showing me. I tried the code... i get "Collector is not a member of Unity.GameObject" .. i change the variable to Object... i get a huge load of Boo errors... What am i ment to set the variable as? Matty
– anon37092856You made your assignment wrong. If you just do "Collector = ..." then it assumes that Collector is some sort of member of Unity script. You need to do something like "GameObject collector = ..." and it will work.
– anon25104582I don't understand.. The variable is stated as a GameObject, Collector being its name, then in the Start function it assigns it as such, thats all fine... I have found a new problem though, Collector is the GameObject, Tackled amount isnt a component.. so it would need to be Collector.Collector.TackledAmount... ??? what!?
– anon37092856I just corrected your syntax in the GUI.Label call. TackledAmount and any other variable you declare can't be part of an gameobject. They must be declared inside a component that you attach to a gameobject, I thought that was obvious. So you'll need to find your script using GameObject.Find("Collector").GetComponent("MyCollectorClass");
– Jake-Lmy issue was a spelling mistake... laugh at me please. All of your ideas would have worked fine... i'm ashamed. Thanks everyone, glad to close this question.
– anon37092856