0
Good afternoon!
I am finishing a C# Quiz made in Unity. The question I have is, I have several questions that I would like to see an Asset. But I need to set the difficulties for each of the issues. And by clicking on the Easy difficulty menu, I want it to only load those questions that are with the selected difficulty. But I am having difficulty. I will put here the code of my class that creates the question.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
[CreateAssetMenuAttribute]
public class QuizQuestion : ScriptableObject {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
//Campos que receberão dados do arquivo .xml ou .json
[SerializeField]
private string pergunta;
[SerializeField]
private string[] respostas;
[SerializeField]
private int respostaCorreta;
//Métodos para buscar as perguntas, opções, resposta correta e dificuldade
public string Pergunta { get { return pergunta; } }
public string[] Respostas { get { return respostas; } }
public int RespostaCorreta { get { return respostaCorreta; } }
//public int Dificuldade { get { return dificuldade; } }
public bool Asked { get; internal set; }
//Validar a resposta
private void OnValidate()
{
if (respostaCorreta > respostas.Length)
{
respostaCorreta = 0;
}
RenomearObjetoDeAcordoComPerguntaResposta();
}
private void RenomearObjetoDeAcordoComPerguntaResposta()
{
string desiredName = string.Format("{0} [{1}]",
pergunta.Replace("?", ""),
respostas[respostaCorreta]);
string assetPath = AssetDatabase.GetAssetPath(this.GetInstanceID());
string shouldEndWith = "/" + desiredName + ".asset";
if (assetPath.EndsWith(shouldEndWith) == false)
{
Debug.Log("Want to rename to " + desiredName);
AssetDatabase.RenameAsset(assetPath, desiredName);
AssetDatabase.SaveAssets();
}
}
}
Thank you in advance!
I don’t see any attribute related to the level of difficulty of
Pergunta
– Leandro Angelo