- Home /
multiple choice quiz game, I had error when I would submit/update the score using toolbar, it increases rapidly, can someone tell me my error is? thank you in advance here is my code.
// The position on of the scrolling viewport var scrollPosition : Vector2 = Vector2.zero;
var textfield : GUIText; public var score : int = 0; // Score var guiSkin : GUISkin; //Background
var Question1ToolbarInt : int = 0; var toolbarStrings1 : String[] = ["A", "B", "C", "D"];
var Question2ToolbarInt : int = 0; var toolbarStrings2 : String[] = ["A", "B", "C", "D"];
var Question3ToolbarInt : int = 0; var toolbarStrings3 : String[] = ["A", "B", "C", "D"];
var Question4ToolbarInt : int = 0; var toolbarStrings4 : String[] = ["A", "B", "C", "D"];
function Awake () { textfield = GameObject.Find("ScoreText").GetComponent(GUIText); // ScoreText is the name of the GUIText }
function OnGUI () {
scrollPosition = GUI.BeginScrollView (Rect (40,40,360,280), //position of the rectangle
scrollPosition, Rect (-130, 0, 1000, 0)); //1000 is the scrollers limit
GUI.Label (Rect (25, 25, 100, 30), "Label");
//QUESTION No.1
Question1ToolbarInt = GUI.Toolbar (Rect (0,160,100,20), Question1ToolbarInt, toolbarStrings1);
//QUESTION No.2
Question2ToolbarInt = GUI.Toolbar (Rect (0,180,100,20), Question2ToolbarInt, toolbarStrings2);
//QUESTION No.3
Question3ToolbarInt = GUI.Toolbar (Rect (0,200,100,20), Question3ToolbarInt, toolbarStrings3);
//QUESTION No.4
Question4ToolbarInt = GUI.Toolbar (Rect (0,220,100,20), Question4ToolbarInt, toolbarStrings4);
if (Question1ToolbarInt == 1)
{
score++;
}
if(GUI.Button(Rect(0,240,100,20), "submit"))
{
UpdateScoreText();
}
// End the scroll view that we began above.
GUI.EndScrollView ();
}
function UpdateScoreText () { // update textfield with score textfield.text = score.ToString(); }