Errors In My Scripts

I am getting some weird errors in my scripts. Please spot the error.

Questions script:-

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

[CreateAssetMenu(menuName = "Question")]

public class Questions : ScriptableObject
{
    [TextArea(1, 5)] [SerializeField] string question = "Question????????????";
    [TextArea(1, 2)] [SerializeField] string[] answers = new string[4];
    [SerializeField] int correctAnswerIndex;

    public string GetQuestion()
    {
        return question;
    }

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

    public int GetCorrectAnswerIndex()
    {
        return correctAnswerIndex;
    }
}

Quiz script:-

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

public class Quiz : MonoBehaviour
{
    [SerializeField] TextMeshProUGUI questionText;
    [SerializeField] Questions question;

    void Start()
    {
        questionText.text = question.GetQuestion();
    }
}

Errors:-

Hi,

First of all, please check if there are two Questions script in your Assets folder. If there aren’t, go to Edit > Preferences > External Tools and try to click the “Regenerate project files” if that button is available.

If that didn’t fix it, what script editor do you use?

I had another script called ‘Questions’. I don’t know how it got there but removing it solved the problem.

Now the project is working fine but there is a red line in ‘Quiz’ script.

Is the TextMeshPro package installed in Unity (Window > Package Manager)?

If so, go to Edit > Preferences > External Tools (in Unity) and click on “Regenerate project files” if the button is available.

Yeah!! that solved it.

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

Privacy & Terms