This is my script. You can see that declared some variables at top:
var QuestAccepted = false;
var TextBoxOnCheck: boolean = false;
var MessageBox: GameObject;
var TextBox: GameObject;
var QuestBox: GameObject;
var QuestText: GameObject;
function OnMouseDown() {
if(!TextBoxOnCheck) {
MessageBox.SetActive(true);
if(!QuestAccepted) {
TextBox.GetComponent.<Text>().text = 'Villager: Hello, some bandit have stollen my money. Could you retrieve it from them on the other side of the river?
[F] to Accept, to refuse.';
}
else {
TextBox.GetComponent.().text = ‘Villager: Get going then!’;
}
}
else {
MessageBox.SetActive(false);
}
TextBoxOnCheck = !TextBoxOnCheck;
}
function CloseMessageBox() {
MessageBox.SetActive(false);
TextBoxOnCheck = false;
}
function AcceptQuest() {
QuestText.GetComponent.<Text>().text = 'Active Quest: Recover the loot';
QuestAccepted = true;
TextBox.GetComponent.<Text>().text = 'Villager: Nice! I\'ll be waiting here, tell me when your job is done!';
//yield WaitForSeconds(3);
//CloseMessageBox();
}
function Update() {
if(Input.GetButtonDown('Use')) {
AcceptQuest();
}
else if(Input.GetButtonDown('Cancel')) {
CloseMessageBox();
}
}
And those are assigned in inspector as I dragged and dropped. When the game starts, all functions works well but this error message is in the console:
UnassignedReferenceException: The variable QuestText of Quest001 has not been assigned.
You probably need to assign the QuestText variable of the Quest001 script in the inspector.
UnityEngine.GameObject.GetComponent