unity-game-enginegame-developmentunityscript

MissingMethodException : UnityEngine.GameObject.setActive


I have added the below script to the NPC. on clicking on to the NPC the MessageBox (Panel in Canvas) should appear. But the MessageBox.setActive() part is not working. Below is the code.

import UnityEngine.UI;

var TextBoxOnCheck : int = 0;
var MessageBox : GameObject;
var TextBox : GameObject;
var TextMessage : String;
var QuestBox : GameObject;
var QuestText : GameObject;
var QuestName : String;

function OnMouseDown(){
    if (TextBoxOnCheck == 0) {
        TextBoxOnCheck = 1;
        MessageBox.setActive(true);
        TextBox.GetComponent.<Text>().text = TextMessage;
        QuestName = "Active Quest: 'Recover the loot'";
        QuestText.GetComponent.<Text>().text = QuestName;
    } else {
        TextBoxOnCheck = 0;
        MessageBox.setActive(false);
        TextMessage = "Villager: Get going then.";
    }
}

Error: enter image description here

Rest of the code like changing QuestText to QuestName when clicking on NPC is working fine.


Solution

  • Typo, s should be capitalized, turn it into .SetActive() instead of .setActive()

    https://docs.unity3d.com/ScriptReference/GameObject.SetActive.html