I have two classes within a script
using UnityEngine;
using System.Collections;
public class QuestionClass2 : MonoBehaviour
{
public Question[] arrayOfQuestions;
public Question currentQuestion;
public bool showQuestion = true;
private int coinToss;
public bool heads;
public bool tails;
//public QuestionClass2 test;
public class Question
{
public int selectedAnswer = -1;
public int correctAnswerIndex;
private string questionText;
private Rect questionRect;
private string[] answers = new string[4];
private string[] displayAnswers = new string[4];
private Rect[] answerRects = new Rect[4];
private string correctAnswer;
private Rect correctRect;
private int questionWidth = 300;
private int answerWidth = 75;
private int questionHeight = 1000;
private int correctWidth = 100;
public Question(Vector2 pos, string q, string a, string b, string c, string d, int correct)
{
questionText = q;
answers[0] = a;
answers[1] = b;
answers[2] = c;
answers[3] = d;
string st = "ABCD";
for(int i = 0; i < answers.Length; i++)
{
displayAnswers <em>= st _+ ": " + answers*;*_</em>
}
correctAnswerIndex = correct;
correctAnswer = "Correct answer: " + answers[correct];
CalcRects (pos);
}
* void CalcRects(Vector2 pos)*
{
* Rect rect = new Rect();*
* rect.x = pos.x;*
* rect.y = pos.y;*
* rect.width = questionWidth;*
* rect.height = questionHeight;*
* questionRect = rect;*
* rect.x += questionWidth;*
* rect.width = answerWidth;*
* for (int i = 0; i < answers.Length; i++)*
* {*
_ answerRects = rect;
* rect.x += answerWidth;
}*_
* rect.width = correctWidth;*
* correctRect = rect;*
}
public void DisplayQuestion()
{
GUI.Label(questionRect, questionText);
for (int i = 0; i < answers.Length; i++)
* {*
GUI.Label(answerRects_, displayAnswers*);
}
if (selectedAnswer != -1)
{
GUI.Label(correctRect, correctAnswer);
}
}*_
* public void CheckForClick(Vector2 pos)*
* {*
* for (int i = 0; i < answers.Length; i++)*
* {*
_ if (answerRects*.Contains(pos))
{
selectedAnswer = i;
break;
}
}
}
}
void OnGUI()
{*
Event e = Event.current;_
if (e.type == EventType.Repaint)
* {*
* //QuestionClass2 script = (QuestionClass2)(GameObject.Find(“QuestionManager”).GetComponent(“QuestionClass2”));*
* currentQuestion.DisplayQuestion();*
* }*
//if (e.type == EventType.MouseDown)
// {
* //foreach(Question thisQ in arrayOfQuestions)*
* // {*
* // thisQ.CheckForClick(e.mousePosition);*
* //}*
// }
}
}
Ive clearly stated that currentQuestion is appart of QuestionClass2 and DisplayQuestion is apart of the QuestionClass, why am i getting an error object reference not set to an instance of object.