Random Questions Spa

Hi,I would spawn random questions from my arrays string questions ideas?

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Answer : MonoBehaviour {
public string[]domande;
private int idDomanda;
private float quesiti;
void Start () {
      
        idDomanda = 0;
        quesiti = domande.Length;
}
////////////////////////
ProssimaDomanda ();

     void ProssimaDomanda()
    {
        idDomanda+= 1;
        if(idDomanda<=(quesiti-1))
}
        }
int rndInstance = (int)Random.Range(0, domande.Length); // Create random int value
string rndQuestion = domande[rndInstance];// Get string for index of this random value

Thanks for your reply where should I add this line?

Where do you want to get the question? :eyes:

1 Like

when I start the game and during the game but if I put those lines everywhere in my code nothing happens

What do you mean by “put those lines everywhere in my code nothing happens”? Nothing visible should happen if you just put them somewhere. These lines just get a random question into the string variable (that was your question mainly about). A question is stored there, but you don’t use it now. You have to put them into UI. I cannot do that for you, because I do not know how your app works. You need to watch some series about UI and about Unity in general, because I suggest that you know too little about programming if you think that those lines would make everything you wanted.

I apologise if I misunderstood. Maybe you try to use them, but it doesn’t work. Then explain more what you are trying to do. But according to your last message, you just put them somewhere. Then, as I said, nothing visible should happen.

1 Like

Well I tried to put them in the function prossima domanda but the order is the same there isn’t a random spawn of the questions

Add one more line to the previous:

Debug.Log(rndQuestion);

What does the console say?

Again, I am unsure what you do. If you again literally just put the lines there, nothing visible will happen. I don’t even see how you are going to display the questions, because you have nothing related to this in ProssimaDomanda function. Do you use Unity UI, or GUI, or maybe something completely different? The line that I asked you to add should show in the console the random question. I also do not understand why and how you decided that my code produced no random question. Probably it did (I might be wrong, need to see the result of debug line).

If you now ask about how to display this random question, then it is completely different story. And I would like to not answer this question, because there are a lot of video tutorials, manuals and articles about it. I can only tell you that you should look for Unity UI information.

Sorry man I don’t want to be rude nobody offend you, in my context probably is my fault ,your advice doesn’t help me. If you have patience and you want help me ,We can try to work togheter .I asked here not cause I’m not able to use Unity I’ve studied and two games are avaible on Play store,I’m not a stupid. I would unserstand what I’m doing ,everyone is capable to copy blindly.
The console works perfectly but the order of the questions ,is the same.The difference betwwin my issue and the other is that I would randomize a string and every questions couldn’t be repeated.