Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 theansweris42 · Sep 29, 2018 at 04:50 AM · listsave dataachievements

How to save answer strings displayed using Random.Range and link to achievements

Hi, I've been trying to find a solution for this but am stuck, so any advice is really appreciated.

Right now, I have a list that is used to display strings in the list at random to the user, using Random.Range. However, those answers are not recorded or saved, so the user has no way of knowing how many of these answers they have unlocked.

This is what I have right now:

 List<string> allLocations = new List<string>();
 
         allLocations.Insert(0, "Answer 1");
         allLocations.Insert(1, "Answer 2");
         allLocations.Insert(2, "Answer 3");
    
  // Display random answer from list
 
         string displayAnswer = allLocations[Random.Range(0, allLocations.Count)];
 

I would like to implement a way to record each displayed string if hasn't been shown to the user before, and sort the string in a list (or more suitable option) according to different categories.

E.g if either of the strings"Answer 1" or "Answer 2" are displayed and it has not been shown to the user before, it will be recorded and count as one answer unlocked in Category A of the achievements. If the string "Answer 3" is displayed to the user for the first time, it will count as one answer unlocked in Category B.

Ideally I would be able to sort these unlocked answer strings, so that the user can see how many of the answers they have unlocked in each category. There are 101 strings of these unlocked answers which are broken down into 10 categories for the achievements.

How do I implement this and make the record of the strings previously displayed to the user accessible to a script displaying achievements? I read that JSON data serialization is better for this than PlayerPrefs, but I am unsure how to implement this.

Thank you! I apologize in advance if this is a stupid question; I'm really new to Unity and C#.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by tormentoarmagedoom · Sep 29, 2018 at 10:48 AM

Good day.

Then the best way i think is to create another array or list with the same length. It can be a int array or string array.

In this new array you store the category of each element of the answers array. If answers[4] is displayed, then store answcategor[4] = "displayede!

I mean each answer have its own information in this new array. You only need to read/write the status in this new array.

Bye!

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
avatar image
0

Answer by Pakillottk · Sep 29, 2018 at 04:05 PM

I suggest that you change your answer list from a string list to something like this:

 [System.Serializable] //This allow us to tweak the values in the inspector
     public class Answer {
           public string text;
           public string category; //maybe should be an enum? I don't know the structure you have, but 
                                   //could be a good idea to do something like that.
           public bool unlocked;
     }    
     //Then your list
     List<Answer> answers //...

This will allow you to filter the list, sort it or do whatever using the data in the list element.

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

94 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

Related Questions

A node in a childnode? 1 Answer

Save / Load List with Prefabs instantiated in the runtime 2 Answers

List Saving Problem 0 Answers

BinaryFormatter - saving and loading a list containing sprites. 0 Answers

hay i am new in saving and loading date in binary formate I wana to save and load list of data 1 Answer


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