2016-08-13 3 views
0

Bitte helfen Sie mir, ich bin ein Neuling mit C# Sprache. Ich habe versucht, einfach Bewerbungsquiz zu machen, aber ich bekomme das Problem, dass ich den Prozess nach der letzten Quizfrage nicht beenden kann. Das Skript, das ich unten haben:Wie beende ich den Prozess meines einfachen Bewerbungsquiz?

using UnityEngine; 
using System.Collections; 
using UnityEngine.UI; 
public class Quiz : MonoBehaviour { 
    [System.Serializable] 
    public class Question{ 
     public string NoSoal; 
     public string TextSoal; 
     public string Pilihan1; 
     public string Pilihan2; 
     public string Pilihan3; 
     public string Pilihan4; 
     public int qKeyAnswer; 
     public int qUserAnswer; 

    } 

    public int BanyakPilihan; 
    public GUISkin mySkin; 
    private float Score; 
    public Question[] pertanyaan; 
    private GameObject coba; 
    private Text nil; 

    private GameObject Canvas; 

    // Use this for initialization 
    void Start() { 
     BanyakPilihan = 0; 
     Score = 0; 
     Canvas=GameObject.Find("Canvas"); 
    } 
    // Update is called once per frame 
    void Update() { 
      } 

    void OnGUI() { 
      GUI.skin = mySkin; 
     GUILayout.BeginArea(new Rect((Screen.width/2)-200, 100 ,400, 450)); 
     GUILayout.Box(Score.ToString("F1")); 
     GUILayout.Label(pertanyaan[BanyakPilihan].TextSoal); 
     if (GUILayout.Button(pertanyaan[BanyakPilihan].Pilihan1,mySkin.button)){ 
      pertanyaan[BanyakPilihan].qUserAnswer = 1; 
      CalculateResult(); 
      GoNextQuestion(); 

     } 
     if (GUILayout.Button(pertanyaan[BanyakPilihan].Pilihan2)){ 
      pertanyaan[BanyakPilihan].qUserAnswer = 2; 
      CalculateResult(); 
      GoNextQuestion(); 

     } 
     if (GUILayout.Button(pertanyaan[BanyakPilihan].Pilihan3)){ 
      pertanyaan[BanyakPilihan].qUserAnswer = 3; 
      CalculateResult(); 
      GoNextQuestion(); 

     } 

     if (GUILayout.Button(pertanyaan[BanyakPilihan].Pilihan4)){ 
      pertanyaan[BanyakPilihan].qUserAnswer = 4; 
      CalculateResult(); 
      GoNextQuestion(); 

     } 
     GUILayout.EndArea(); 
    } 

    void GoNextQuestion(){ 

     if (BanyakPilihan < pertanyaan.Length-1){ 
      BanyakPilihan++; 

     } 
    }  

    void CalculateResult(){ 
     float Total = 0; 
     for (int i=0; i< pertanyaan.Length; i++){ 
      if (pertanyaan[i].qKeyAnswer == pertanyaan[i].qUserAnswer){ 
       Total = Total + 1; 
      } 
     } 
     Total = Total/pertanyaan.Length * 100; 
     Score = Total; 
    } 
} 

Bitte helfen Sie mir, dieses Problem zu lösen.

Antwort

1

Sie konnten dieses versuchen:

void GoNextQuestion(){ 
    GUI.skin=mySkin; 
    GUILayout.BeginArea(new Rect((Screen.width/2)-200, 100 ,400, 450)); 

    if (BanyakPilihan < pertanyaan.Length-1){ 
     BanyakPilihan++; 
    } else { 
     MessageBox.Show("The end"); 
     Application.Exit(); 
    } 
}  
+0

Anwendung nicht sir laufen kann. und ich möchte nach der letzten Quizfrage nach Hause zurückkehren oder es noch einmal wiederholen. Danke –

+0

Sie könnten versuchen, die 'BanyakPilihan'-Variable zurückzusetzen. –

+0

Ich muss es versuchen, kann aber nicht in Unity3D laufen. "Der Name MessageBox existiert nicht" Wie behebt man? –