Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by FerdianDN · Oct 26, 2021 at 01:46 PM · scripting problemsavesave datasaveloadsave game

I want to save my level progress in my quiz game

alt text

so this is my game, word quiz game. Every answer correct, it goes to next question. the problem is i have no idea how to save the progress of question so if i quit game or back to main menu, the question doesn't back to question #1 again. pls help me. here are the code :

 using System;
 using System.Collections;
 using System.Collections.Generic;
 using System.Linq;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class QuizManager2 : MonoBehaviour
 {
     public static QuizManager2 instance; //Instance to make is available in other scripts without reference
 
     [SerializeField] private GameObject gameComplete, MainMenu, GameMenu;
     [SerializeField] private Text currentQuestion;
     [SerializeField] private QuizDataScriptable2 QuizDataList;    //Scriptable data which store our questions data
     [SerializeField] private Image questionImage;           //image element to show the image
     [SerializeField] private WordData[] answerWordList;     //list of answers word in the game
     [SerializeField] private WordData[] optionsWordList;    //list of options word in the game
     
 
     public Text CurrentQuestion { get { return currentQuestion; } }
     
 
     private int scoreCount = 1;
     
     private GameStatus gameStatus = GameStatus.Playing;     //to keep track of game status
     private char[] wordsArray = new char[18];               //array which store char of each options
 
     private List<int> selectedWordsIndex;                   //list which keep track of option word index w.r.t answer word index
     private int currentAnswerIndex = 0, currentQuestionIndex = 0;   //index to keep track of current answer and current question
     private bool correctAnswer = true;                      //bool to decide if answer is correct or not
     private string answerWord;                              //string to store answer of current question
 
     private void Awake()
     {
         if (instance == null)
             instance = this;
         else
             Destroy(this.gameObject);
     }
 
     // Start is called before the first frame update
     void Start()
     {
         scoreCount = 1;
         
 
         selectedWordsIndex = new List<int>();           //create a new list at start
         SetQuestion();                                  //set question
 
     }
     
    
 
    
 
     void SetQuestion()
     {
         gameStatus = GameStatus.Playing;                //set GameStatus to playing 
 
         //set the answerWord string variable
         answerWord = QuizDataList.questions[currentQuestionIndex].answer;
         //set the image of question
         questionImage.sprite = QuizDataList.questions[currentQuestionIndex].questionImage;
             
         ResetQuestion();                               //reset the answers and options value to orignal     
 
         selectedWordsIndex.Clear();                     //clear the list for new question
         Array.Clear(wordsArray, 0, wordsArray.Length);  //clear the array
 
         //add the correct char to the wordsArray
         for (int i = 0; i < answerWord.Length; i++)
         {
             wordsArray[i] = char.ToUpper(answerWord[i]);
         }
 
         //add the dummy char to wordsArray
         for (int j = answerWord.Length; j < wordsArray.Length; j++)
         {
             wordsArray[j] = (char)UnityEngine.Random.Range(65, 90);
         }
 
         wordsArray = ShuffleList2.ShuffleListItems<char>(wordsArray.ToList()).ToArray(); //Randomly Shuffle the words array
 
         //set the options words Text value
         for (int k = 0; k < optionsWordList.Length; k++)
         {
             optionsWordList[k].SetWord(wordsArray[k]);
         }
 
     }
 
     //Method called on Reset Button click and on new question
     public void ResetQuestion()
     {
         //activate all the answerWordList gameobject and set their word to "_"
         for (int i = 0; i < answerWordList.Length; i++)
         {
             answerWordList[i].gameObject.SetActive(true);
             answerWordList[i].SetWord('_');
         }
 
         //Now deactivate the unwanted answerWordList gameobject (object more than answer string length)
         for (int i = answerWord.Length; i < answerWordList.Length; i++)
         {
             answerWordList[i].gameObject.SetActive(false);
         }
 
         //activate all the optionsWordList objects
         for (int i = 0; i < optionsWordList.Length; i++)
         {
             optionsWordList[i].gameObject.SetActive(true);
         }
 
         currentAnswerIndex = 0;
     }
 
     /// <summary>
     /// When we click on any options button this method is called
     /// </summary>
     /// <param name="value"></param>
     public void SelectedOption(WordData value)
     {
         //if gameStatus is next or currentAnswerIndex is more or equal to answerWord length
         if (gameStatus == GameStatus.Next || currentAnswerIndex >= answerWord.Length) return;
 
         selectedWordsIndex.Add(value.transform.GetSiblingIndex()); //add the child index to selectedWordsIndex list
         value.gameObject.SetActive(false); //deactivate options object
         answerWordList[currentAnswerIndex].SetWord(value.wordValue); //set the answer word list
 
         currentAnswerIndex++;   //increase currentAnswerIndex
 
         //if currentAnswerIndex is equal to answerWord length
         if (currentAnswerIndex == answerWord.Length)
         {
             correctAnswer = true;   //default value
             //loop through answerWordList
             for (int i = 0; i < answerWord.Length; i++)
             {
                 //if answerWord[i] is not same as answerWordList[i].wordValue
                 if (char.ToUpper(answerWord[i]) != char.ToUpper(answerWordList[i].wordValue))
                 {
                     correctAnswer = false; //set it false
                     break; //and break from the loop
                 }
             }
 
 
             //if correctAnswer is true
             if (correctAnswer)
             {
                 
                 scoreCount += 50;
                 currentQuestion.text = "Score:" + scoreCount;
                 Debug.Log("Correct Answer");
                 gameStatus = GameStatus.Next; //set the game status
                 currentQuestionIndex++; //increase currentQuestionIndex
 
                 //if currentQuestionIndex is less that total available questions
                 if (currentQuestionIndex < QuizDataList.questions.Count)
                 {
                     Invoke("SetQuestion", 0.5f); //go to next question
                 }
                 else
                 {
                     Debug.Log("Game Complete"); //else game is complete
                     gameComplete.SetActive(true);
                 }
             }
         }
     }
 
     public void ResetLastWord()
     {
         if (selectedWordsIndex.Count > 0)
         {
             int index = selectedWordsIndex[selectedWordsIndex.Count - 1];
             optionsWordList[index].gameObject.SetActive(true);
             selectedWordsIndex.RemoveAt(selectedWordsIndex.Count - 1);
 
             currentAnswerIndex--;
             answerWordList[currentAnswerIndex].SetWord('_');
         }
     }
 
     
 
 }
 
 [System.Serializable]
 public class QuestionData2
 {
     public Sprite questionImage;
     public string answer;
 }
 
 public enum GameStatus
 {
    Next,
    Playing
 }
 

   







screenshot-2021-10-26-20-12-54-82-26c2692d332804a4.jpg (437.4 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by FerdianDN · Oct 26, 2021 at 01:47 PM

Pls help me (T_T)

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

233 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to make a list of saves and load them correctly 0 Answers

Save Game Sceenes user quit aplication, Can I save the scene as a whole while leaving the game? 0 Answers

How to save user levels? 0 Answers

Save progress in WebGL game (C#) 1 Answer

Saving progress even when I quit the windows app 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges