// Start is called before the first frame update
    void Start()
    {
        questionText.text = QuestionDataScript.getQuestion();

        string[] answers = QuestionDataScript.getAnswers();
        answerOneButton.GetComponentInChildren <Text>().text = answers[0];
        answerTwoButton.GetComponentInChildren <Text>().text = answers[1];

        if (answers.Length > 2)
        {
            answerThreeButton.GetComponentInChildren <Text>().text = answers[2];
            if (answers.Length > 3)
            {
                answerFourButton.GetComponentInChildren <Text>().text = answers[3];
            }
            else
            {
                answerFourButton.GetComponentInChildren <Text>().text = "";
                answerFourButton.interactable = false;
            }
        }
        else
        {
            answerThreeButton.GetComponentInChildren <Text>().text = "";
            answerThreeButton.interactable = false;
            answerFourButton.GetComponentInChildren <Text>().text = "";
            answerFourButton.interactable = false;
        }

        answerOneButton.onClick.AddListener(AnswerOneButtonOnClick);
        answerTwoButton.onClick.AddListener(AnswerTwoButtonOnClick);
        answerThreeButton.onClick.AddListener(AnswerThreeButtonOnClick);
        answerFourButton.onClick.AddListener(AnswerFourButtonOnClick);
    }
    void Update()
    {
        if (!answered)
        {
            timeQuestion       -= Time.deltaTime;
            timerBar.fillAmount = timeQuestion / 60.0f;

            if (timeQuestion >= 30.0f)
            {
                timerBar.color = Color.green;
            }
            else if (timeQuestion >= 15.0f)
            {
                timerBar.color = Color.yellow;
            }
            else if (timeQuestion >= 0.0f)
            {
                timerBar.color = Color.red;
            }
            else
            {
                SoundManager.PlayAnswerSound(false);
                answersNonInteractable();
                GameBehaviourScript.SendJugada(QuestionDataScript.getPosition(), "", true, false);
                StartCoroutine(WaitAndExit(1));
            }
        }
    }
 private void AnswerThreeButtonOnClick()
 {
     answersNonInteractable();
     answered = true;
     if (QuestionDataScript.getCorrectAnswer() == 2)
     {
         string quesito = QuestionDataScript.getCategory();
         Debug.Log("GETQUESITO" + QuestionDataScript.getQuesito());
         if (QuestionDataScript.getQuesito())
         {
             activateQuesito(quesito);
         }
         answerThreeButton.GetComponent <Image>().color = Color.green;
         SoundManager.PlayAnswerSound(true);
         addCoin();
         GameBehaviourScript.SendJugada(QuestionDataScript.getPosition(), QuestionDataScript.getQuesito() ? quesito : "", false, false);
     }
     else
     {
         answerThreeButton.GetComponent <Image>().color = Color.red;
         SoundManager.PlayAnswerSound(false);
         GameBehaviourScript.SendJugada(QuestionDataScript.getPosition(), "", true, false);
     }
     StartCoroutine(WaitAndExit(2));
 }
    //Recibe el resultado de la pregunta
    public static void SendJugada(int casilla, string quesito, bool finTurno, bool esDado)
    {
        Debug.Log("SendJugada: " + casilla + quesito + finTurno + esDado);
        JObject args = new JObject(new JProperty("casilla", casilla), new JProperty("quesito", quesito), new JProperty("finTurno", finTurno));

        SocketioHandler.socket.Emit("actualizarJugada", (trash) => { Debug.Log("actualizarJugada = " + trash); return; }, args);

        if (!finTurno && !esDado)
        {
            QuestionDataScript.func();
        }
    }
    //Genera la pregunta de la casilla
    private void newQuestion(bool quesito, string category, string question, string correct, List <string> incorrects, int position)
    {
        //Lo mezcla, genera la posicion e inserta la respuesta correcta ahí
        Shuffle(ref incorrects);
        int idCorrect = UnityEngine.Random.Range(0, incorrects.Count + 1);

        incorrects.Insert(idCorrect, correct);

        QuestionDataScript.setQuestion(question, incorrects, idCorrect, quesito, category, position, () => StartCoroutine(turno((UserDataScript.getInfo("username")))));

        SceneManager.LoadScene("Question Scene", LoadSceneMode.Additive);
    }
 void Start()
 {
     soundEffects     = GameObject.Find("Sounds").GetComponent <SoundEffectsHelper>();
     mainQuestions    = GameObject.Find("MainInterface").GetComponent <QuestionDataScript>();
     toggleMenuButton = GameObject.Find("MainInterface/ToggleMenu").GetComponent <Image>();
 }
Beispiel #7
0
 // Use this for initialization
 void Start()
 {
     questionData = GameObject.Find("MainInterface").GetComponent <QuestionDataScript>();
     soundEffects = GameObject.Find("Sounds").GetComponent <SoundEffectsHelper>();
 }