EDIT in response to evolved question / problem:
Looks like my previous answer didn't help prevent multiple OnGUI() calls from running the whole section of script, sorry about that. Here's a solution that will definitely work:
Your testQuestionThree function should look like this:
void testQuestionThree(){
if(popUpDisplayed == false)
{
if(allObjectsClicked)
{
if(isClicked == false)
{
GUI.Box (new Rect (350,10,350,120), "Please click the learning cube.");
}//end isClicked false
}
if(isClicked)
{
if(finalClick == "learningCube2")
{
GUI.Box(new Rect (350, 10, 350, 120), "That was correct. You may now continue.");
}
else
{
GUI.Box(new Rect (350, 10, 350, 120), "Sorry, the correct answer was the cube. Click to advance.");
}
navButtonEnabled = true;
}//end if isClicked
}//end popUpDisplayed
}
The upper part has been moved to update in this form:
void Update () {
if ( Input.GetMouseButtonDown(0) && !popUpDisplayed)
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Physics.Raycast (ray, out hit, 100.0f))
{
if(hit.collider.gameObject.name == "learningCylinder2")
{
object1Clicked = true;
}
if(hit.collider.gameObject.name == "learningCube2")
{
object2Clicked = true;
}
// below we add a test, to see if we clicked either object,
// but importantly this only matters if we've clicked both already.
// this determines what we clicked after the request
if(object1Clicked && object2Clicked)
{
allObjectsClicked = true;
object1Clicked = false; //resetting variables to false
object2Clicked = false;
}
if((object1Clicked || object2Clicked) && allObjectsClicked)
{
isClicked = true;
finalClick = hit.collider.gameObject.name;
allObjectsClicked = false; //resetting variables to false.
object1Clicked = false;
object2Clicked = false;
}
}//end physics
}//end input.get
}
This ensures that the check for mousedown is only done once per frame, and fixes the issues that were presented by multiple OnGUI Calls. The script itself isn't changed so much as cut into two parts and moved. It's important to keep the OR (||) operand.
finalClick as a variable will need to be declared ahead of time, setting = "" is fine.
Now, I assume you're going to want more test questions in your interactive. Leaving this as is will only work for test question three. If all of your questions involve two objects, then you can use a variable to store the name to test against the clicked object, and not much needs to be changed. If each question has its own dynamic, you might want to turn the stuff we moved to update into a second function, and just have two functions per question; one for the GUI display, and one for the mechanics.