Instantiate Image buttonImage

Hi there,

Since Image buttonImage; is called in both OnAnswerSelected and SetDefaultButtonSprites methods.

Instead of instanciating it for each method, would not it be better to instanciate it only once in the class Quiz before the Start method ?

[SerializeField] TextMeshProUGUI questionText;
    [SerializeField] QuestionSO question;
    [SerializeField] GameObject[] answerButtons;
    int correctAnswerIndex;
    [SerializeField] Sprite defaultAnswerSprite;
    [SerializeField] Sprite CorrectAnswerSprite;
    **Image buttonImage;**
    void Start()
    {
        DisplayQuestion();
    }```

Hi,

What exactly do you mean by instantiating? I do not see any instantiation in your code.

Privacy & Terms