Using UnityEngine;
using System.Collections;
Using System. Xml;
Using System. IO;
using System;
Public class queswitch: MonoBehaviour {
Public GameObject [] quechoice;
Private int no1=1, no2=1, quesno=0, stuno=0;
Private bool input1, input2;
Public AudioClip sound;
Private AudioSource Sound;
//Use this for initialization
Void the Start () {
Sound=GameObject. Find (" wall003 "). The GetComponent
CreateXML ();
}
//Update is called once per frame
void Update () {
//quechoice [] is 0 ~ 5 of 6 gameobject, quechoice [1]=A.q uechoice [2]=B.q uechoice [3]=C.q uechoice [4]=D
If (Input. GetKeyDown (KeyCode. X)) {//down when press "X" key to choose
No. + +;
Input1=true;
If (input1) {
If (no1 & gt; 5) {
No1=1;
}
//no2=6 - no.
Input1=false;
}
//the current option of color to red, a color reduction, no1 for options
Quechoice [no1-1]. GetComponent
Quechoice [no] GetComponent
Quechoice [r]. (no. + 1) % 5 GetComponent
Quechoice [r]. (no. + 2) % 5 GetComponent
Quechoice [r]. (no. + 3) % 5 GetComponent
Quechoice [r]. (no. + 4) % 5 GetComponent
}
If (Input. GetKeyDown (KeyCode. Z)) {//when press "Z" key up choose
No1 -;
Input2=true;
If (input2) {
If (no1 & lt; 1) {
No1=5;
}
//no1=6 - no2;
Input2=false;
}
Quechoice [r]. (no. + 1) % 5 GetComponent
Quechoice [r]. (no. + 2) % 5 GetComponent
Quechoice [r]. (no. + 3) % 5 GetComponent
Quechoice [r]. (no. + 4) % 5 GetComponent
Quechoice [no] GetComponent
}
if (Input GetKeyDown (KeyCode. Q)) {
Sound. PlayOneShot (Sound, 1);
Quesno++;
The switch (quesno)
{
Case 1:
GameObject. Find (" questext "). GetComponent
Addxmldata (quesno stuno, no1);
break;
Case 2:
GameObject. Find (" questext "). GetComponent
Addxmldata (quesno stuno, no1);
break;
Case 3:
GameObject. Find (" questext "). GetComponent
Addxmldata (quesno stuno, no1);
break;
Case 4:
GameObject. Find (" questext "). GetComponent
Addxmldata (quesno stuno, no1);
break;
Case 5:
GameObject. Find (" questext "). GetComponent
Addxmldata (quesno stuno, no1);
break;
Case 6:
GameObject. Find (" questext "). GetComponent
Addxmldata (quesno stuno, no1);
break;
Case 7:
GameObject. Find (" questext "). GetComponent
Addxmldata (quesno stuno, no1);
break;
Case 8:
GameObject. Find (" questext "). GetComponent
Addxmldata (quesno stuno, no1);
break;
Case 9:
GameObject. Find (" questext "). GetComponent
Addxmldata (quesno stuno, no1);
break;
Case 10:
GameObject. Find (" questext "). GetComponent
Addxmldata (quesno stuno, no1);
break;
Default:
GameObject. Find (" questext "). GetComponent
Stuno++;//need to modify the record only one person, the character information will be overwritten after
break;
}
}
}
Void CreateXML ()
{
String path=Application. DataPath + "/the XML";
if(! File. The Exists (path))
{
//create the most on a layer of nodes,
XmlDocument XML=new XmlDocument ();
//create the most on a layer of nodes,
XmlElement root=XML. The CreateElement method (" objects ");
//the last save file
XML. The Save (path);
}
}
Void addxmldata (int stuno, int quesno, int queschoice) {//to answer the question of student number, number, answer the questions by the selected options
String path=Application. DataPath + "/the XML";
String a=System. The Convert. ToString (stuno);
String b=System. The Convert. ToString (quesno);
String c=System. The Convert. ToString (queschoice);
If (the File. The Exists (path))
{
XmlDocument XML=new XmlDocument ();
XML. The Load (path);
If (b=="1") {//a new classmate
XmlNode root=XML. SelectSingleNode (" objects ");
XmlElement element=XML. The CreateElement method (" answer ");//student no.
.Element. The SetAttribute (" id ", a);
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull