Error with "QuestionSO question;"

Hey there,

got a minor problem. Maybe someone can help.

Unity is giving me this error: “Assets\Scripts\Quiz.cs(10,22): error CS0246: The type or namespace name ‘QuestionSO’ could not be found (are you missing a using directive or an assembly reference?)”

Quiz Script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;


public class Quiz : MonoBehaviour
{
    [SerializeField] TextMeshProUGUI questionText;
    [SerializeField] QuestionSO question;
    void Start()
    {
        questionText.text = question.GetQuestion();
    }
}

Screenshot 2021-12-21 205354

QuestionSO Script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[CreateAssetMenu (menuName = "Quiz Question", fileName = "New Question")]
public class Question : ScriptableObject
{
    [TextArea(2,6)]
	[SerializeField] string question = "Enter new quastion text here";
    [SerializeField] string[] answers = new string[4];
    [SerializeField] int corrrectAnswerIndex;


    public string GetQuestion()
	{
		return question;
	}

    public string GetAnswer(int index)
	{
		return answers[index];
	}

    public int GetCorrectAnswerIndex()
	{
		return corrrectAnswerIndex;
	}
}

I already checked if there are two QuestionSO scripts in my Assets folder. I also tryed Edit > Preferences > External Tools and clicked the “Regenerate project files”.

Nothing worked so far.

Found it!
The QuestionSO Scipt has the class name “Question”. But it should match Name of the .cs file.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms