Y
Y
Yuri Yanin2019-12-31 01:12:07
C++ / C#
Yuri Yanin, 2019-12-31 01:12:07

What is the best way to use data generated in scripts in Unity3d?

I am writing a small mobile game. To simplify the essence of the issue, all further descriptions are conditional and have nothing to do with reality. There is a game session during which the player is asked questions based on the generated answers. When the player starts the game, the script randomly selects the "answer" from the xml data and writes it to a variable, and on its basis forms the text of the question and passes it to the gameObject text. The question is how best to deal with this answer in the future. I will need to check it with the data entered in the text field. In my head, I figured out several options, and since I am a beginner, I don’t really understand which of these is the more correct or convenient option, and what kind of rake I will step on by choosing one or another option. Actually they are:
1. Create a separate, hidden game object in which the current response selected by the script will be written, and then I can access it from other scripts that will be in the future.
2. Create a separate xml file "session" in which the response is written by the same script and then I refer to it from other scripts. (for me it looks like the most correct option at the moment)
3. Somehow directly access the variable in the script from another script at any time I need. (I think this option will not work at all. Since the script uses the generation of a random number to select an answer, and in theory, I will constantly generate a new number by referring to it, regardless of which one it generated and wrote to the variable when the game started)
That's all. I hope you tell me how to do it better or maybe there are some other options that I did not think about. Any thoughts?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
p4p, 2019-12-31
@p4p

Do you know how to store data? Ask a question in a nutshell, when I read the end of your question, I already forgot the beginning.
If you need to temporarily store answers, you can use a static dictionary, if you save until the next run, then xml / json / sqlite as you like.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question