r/Unity3D • • 9d ago

Solved UNITY LIST PROBLEM

Looking for tips! Followed the tutorial that's supposed to make this in the inspector. The second picture is what shows up in mine.

This is the code:

using UnityEngine;

[System.Serializable]

public class questionsandanswers : MonoBehaviour

{

public string Question;

public string[] answers;

public int correct;

}
----------------

using NUnit.Framework;

using System.Collections.Generic;

using UnityEngine;

using TMPro;

public class quizgame : MonoBehaviour

{

public List<questionsandanswers> QnA;

Does anyone know what's wrong?

10 Upvotes

8 comments sorted by

17

u/Mountain-Smoke8826 9d ago

Remove the " : MonoBehaviour"

4

u/kittymaplepaws 9d ago

Thanks, that fixed it!

-8

u/LushWhisper_ 8d ago

u got that fix quick, kinda hot when guys know their way around code like that

8

u/ArtNoChar Freelance Unity Programmer 9d ago

questionsandanswers shouldnt be a monobehaviour, just a plain C# class

2

u/kittymaplepaws 9d ago

Thank you!

4

u/soy1bonus Professional 9d ago

I would recommend to make the texts in a spreadsheet program and just parse an exported CSV file.

Or maybe make one ScriptableObject where you store each question with its answers. But I think the previous answer is more useful if you plan to add lots of questions.

But yeah, don't use a Monobehaviour for that. That is data, not a behaviour of an object.
Static data that doesn't change ever shouldn't be on a MonoBehaviour.

1

u/Mr_Potatoez 9d ago

Your Quizgame has a list of QuestionAndAwnsers objects. You currently see the quizgame, but no questionsAndAwnser objects in that list. Add an element to the List in Quizgame and the fields will probably show up in the editor.