Scripting with Variables error message
Posted: Sat May 29, 2021 8:14 pm
Hi,
I am trying to get a variable that I had created in the Dialogue Manager for scripting. I've looked at other posts but I am not sure why they have not gotten the same error.
Error Message:
UnityException: get_isDebugBuild is not allowed to be called from a MonoBehaviour constructor (or instance field initializer), call it in Awake or Start instead. Called from MonoBehaviour 'ScoreCounter' on game object 'Text'.
-I am new to coding and it looks like it need to use something else but I am not sure what.
Script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using PixelCrushers;
using PixelCrushers.DialogueSystem;
public class ScoreCounter: MonoBehaviour
{
int gold;
void Update()
{
int gold = DialogueLua.GetVariable("playerGold").asInt;
Debug.Log(gold);
}
}
The eventual goal is to keep track of gold and other resources in the dialogue manager and then have it displayed to the player as UI using Unity UI and script.
Thanks for your time,
I am trying to get a variable that I had created in the Dialogue Manager for scripting. I've looked at other posts but I am not sure why they have not gotten the same error.
Error Message:
UnityException: get_isDebugBuild is not allowed to be called from a MonoBehaviour constructor (or instance field initializer), call it in Awake or Start instead. Called from MonoBehaviour 'ScoreCounter' on game object 'Text'.
-I am new to coding and it looks like it need to use something else but I am not sure what.
Script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using PixelCrushers;
using PixelCrushers.DialogueSystem;
public class ScoreCounter: MonoBehaviour
{
int gold;
void Update()
{
int gold = DialogueLua.GetVariable("playerGold").asInt;
Debug.Log(gold);
}
}
The eventual goal is to keep track of gold and other resources in the dialogue manager and then have it displayed to the player as UI using Unity UI and script.
Thanks for your time,