Value cannot be null, parameter _unity_self problem

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

[CreateAssetMenu(fileName = “New Quiz”, menuName = “Quiz Question”, order = 0)]

public class QuestionSO : ScriptableObject {

[TextArea (4 ,6)]

[SerializeField] string question = "Enter The Quiz";

[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;

}

}

==============================================================================

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using TMPro;

using UnityEngine.UI;

public class Quiz : MonoBehaviour

{

[SerializeField]TextMeshProUGUI questionText;

[SerializeField]QuestionSO question;

[SerializeField] GameObject[] answerButtons;

int correctAnswerIndex;

[SerializeField] Sprite defaultAnswerSprite;

[SerializeField] Sprite correctAnswerSprite;

void Start()

{

    questionText.text = question.getQuestion();

    for (int i = 0; i< answerButtons.Length; i++)

    {

        TextMeshProUGUI buttonText = answerButtons[i].GetComponentInChildren<TextMeshProUGUI>();buttonText.text = question.getanswer(i);

    }

}

public void OnAnswerSelected(int index)

{

    if (index == question.getCorrectAnswerIndex())

    {

        questionText.text = "BENARRR!!";

        Image buttonImage = answerButtons[index].GetComponent<Image>();

        buttonImage.sprite = correctAnswerSprite;

    }

}

}

This has nothing to do with your code, it’s a common Unity error. Restarting Unity usually makes it go away for a while

solved, thank u very much :slight_smile:

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

Privacy & Terms