Home > other >  The unitity XML data to recognize the game in Chou Chou ~ great spirit poking come in and have a loo
The unitity XML data to recognize the game in Chou Chou ~ great spirit poking come in and have a loo

Time:09-22

Here are all the script code, may be long, the main implementation is to record the user, qid and the ABCD option selected, including the update includes select options and confirm the content of the option (only related to write XML standard, the content of the red) the place where the error is in the position of the yellow word,
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 (a);
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 (a). Material. Color=new Color32 (44109118, 0);
Quechoice [no] GetComponent (a). The material. Color=color. Red;
Quechoice [r]. (no. + 1) % 5 GetComponent (a). Material. Color=new Color32 (44109118, 0);
Quechoice [r]. (no. + 2) % 5 GetComponent (a). Material. Color=new Color32 (44109118, 0);
Quechoice [r]. (no. + 3) % 5 GetComponent (a). Material. Color=new Color32 (44109118, 0);
Quechoice [r]. (no. + 4) % 5 GetComponent (a). Material. Color=new Color32 (44109118, 0);

}

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 (a). Material. Color=new Color32 (44109118, 0);
Quechoice [r]. (no. + 2) % 5 GetComponent (a). Material. Color=new Color32 (44109118, 0);
Quechoice [r]. (no. + 3) % 5 GetComponent (a). Material. Color=new Color32 (44109118, 0);
Quechoice [r]. (no. + 4) % 5 GetComponent (a). Material. Color=new Color32 (44109118, 0);
Quechoice [no] GetComponent (a). The material. Color=color. Red;

}
if (Input GetKeyDown (KeyCode. Q)) {
Sound. PlayOneShot (Sound, 1);
Quesno++;
The switch (quesno)
{
Case 1:
GameObject. Find (" questext "). GetComponent (a). The text="1";
Addxmldata (quesno stuno, no1);
break;
Case 2:
GameObject. Find (" questext "). GetComponent (a). The text="of" the second question;
Addxmldata (quesno stuno, no1);
break;
Case 3:
GameObject. Find (" questext "). GetComponent (a). The text="number three";
Addxmldata (quesno stuno, no1);
break;
Case 4:
GameObject. Find (" questext "). GetComponent (a). The text="fourth";
Addxmldata (quesno stuno, no1);
break;
Case 5:
GameObject. Find (" questext "). GetComponent (a). The text="5";
Addxmldata (quesno stuno, no1);
break;
Case 6:
GameObject. Find (" questext "). GetComponent (a). The text="sixth question";
Addxmldata (quesno stuno, no1);
break;
Case 7:
GameObject. Find (" questext "). GetComponent (a). The text="number 7";
Addxmldata (quesno stuno, no1);
break;
Case 8:
GameObject. Find (" questext "). GetComponent (a). The text="eighth problem";
Addxmldata (quesno stuno, no1);
break;
Case 9:
GameObject. Find (" questext "). GetComponent (). The text="ninth problem";
Addxmldata (quesno stuno, no1);
break;
Case 10:
GameObject. Find (" questext "). GetComponent 10 (). The text="";
Addxmldata (quesno stuno, no1);
break;
Default:
GameObject. Find (" questext "). GetComponent (a). The text=thank you "the end";
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
  • Related