So I am making a quiz for a school assignment and at the end of the quiz I want it to tell you in a GUI how many questions you did not answer correctly. I have a static variable called counter and I have tested it and it carries on through different scenes. But how would I display it in my current GUI? Here is my current code
var pietext : GUIText;
function Update () {
pietext.text = "You missed " + counter + " out of 10 questions";
}
As expected it comes up as "unknown identifier “counter” ".
If you’re accessing counter from a member function in the same class that counter is declared in, then you can access it without a type identifier. Otherwise you need to put the class name before you can access it.
And I always use .ToString(). I don’t know if js has an implicit conversion, but C# requires you to explicitly convert one to the other.
pietext.text = "You missed " + ClassName.counter.ToString() + " out of 10 questions";
ClassName will be the name of the script file (Unity automagically creates a class with the same name as the script file).