Click here to Skip to main content
15,919,613 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
C#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class QuizManager : MonoBehaviour
{
    public List<QuestionAndAnswers> QnA;
    public GameObject[] options;
    public int currentQuestion;

    public Text QuestionTxt;

    private void Start()
    {
        QnA.RemoveAt(currentQuestion);
        generateQuestion();
    }

    void SetAnswers()
    {
        for(int i = 0; i< options.Length; i++)
        {
            options[i].GetComponet<AnswerScript>.isCorrect = false;
            options[i].transform.GetChild(0).GetComponet
             <Text>().text = QnA[currentQuestion].Answer[i];
        
            if(QnA[currentQuestion].CorrectAnswer == i+1)
            {
                options[i].GetComponet<AnswerScript>.isCorrect = true;
            }
        }
    }

    void generateQuestion()
    {
        currentQuestion = Random.Range(0,QnA.Count);

        QuestionTxt.text= QnA[currentQuestion].Question;
        SetAnswers();
    }
}


What I have tried:

I am trying to make a Quiz.
I am watching How to make a Quiz Game with Multiple Choices in Unity - YouTube[^]

I got the following error:

Assets\QuizManager.cs(11,12): error CS0246: The type or namespace name 'Text' could not be found (are you missing a using directive or an assembly reference?)


Please help me!
Posted
Updated 13-Sep-23 4:34am
v2

Add "Using UnityEngine.UI" and it resolves the issue. Hope you have the correct version of UnityEngine refrence.

Link :https://docs.unity3d.com/2017.3/Documentation/ScriptReference/UI.Text.html
 
Share this answer
 
The error message tells you exactly what is wrong. It can't find a thing called 'Text'. It even asks if you're missing a using directive. The video you referenced even shows the using statement you need being added when the object is added on the screen.

The 'Text' object is under UnityEngine.UI. You need to add a using statement for it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900