pls help!! I’m trying to create a multiple choice kinda game where the user wud b able to answer some questions shown on the screen. Now here’s the problem, i want to store a sizable amount of questions (and answers) in arrays bcos there wud be a lot of them and coding them wud take forever. and i got a code online of how i cud get that done but when i tried to attach the script to my main camera, it gives me an error description of “Cant add script behaviour question, The script needs to derive from monobehaviour” pls i’m new to unity and i dont knw what this error means. the code compiled well in monoDevelop but can’t be attached to any game object. Pls any help wud be greatly appreciated. Thanks in advance
Here’s the code i used
#pragma strict
var arrayOfQuestions : Question [];
class Question
{
var questionText : String;
var answerText : String;
/* example constructor (creates a Question from two params) */
function Question ( q : String, a : String )
{
questionText = q;
answerText = a;
}
}
/* initialize the question array in the start function */
function Start ()
{
arrayOfQuestions = new Question [20];
/* use a for loop to create dummy questions */
for ( var i = 0; i < 20; i ++ ) {
var someQ : String = "Question number: " + i;
var someA : String = "Answer number: " + i;
/* use the example constructor from above */
var freshQuestion : Question = new Question(someQ, someA);
arrayOfQuestions *= freshQuestion;*
}
}
/* test it */
function OnGUI ()
{
var labelRect : Rect = Rect(200, 200, 300, 30);
for ( var thisQ : Question in arrayOfQuestions ) {
var txt = "Q: " + thisQ.questionText + " A: " + thisQ.answerText;
GUI.Label(labelRect, txt);
labelRect.y += labelRect.height;
}
}