-2

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.

1
  • 2
    That looks like a simple typo: setActive != SetActive ... what Unity version are you using? unityscript was deprecated years ago ... Commented Feb 8, 2022 at 10:16

1 Answer 1

1

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

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

Sign up to request clarification or add additional context in comments.

1 Comment

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.