Error Message

I have done the exact same code as in the video and I still get an error message.

Here’s my code:

According to the error message, QuestionSO does not have a publicly accessible function called GetQuestion. Make sure that it has a function called GetQuestion, and that it is public?

I’m a beginner at coding with Unity and C# and I don’t understand. Could you please explain the solution in more detail?

You made a class called QuestionSO. It should look something like this

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

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

    // YOU HAVE TO MAKE SURE THIS IS HERE
    public string GetQuestion()
    {
        return question;
    }

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

You must make sure it looks like this

Thank you so much!

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

Privacy & Terms