doc/unity/en/knowjs/debugging.md
Here, we recommend using VSCode for debugging. But if you are debugging on mobile, we recommend that you refer to the development blog.
// 8080 is the port used for connection, which should match the setting in .vscode\launch.json under the VSCode project directory.
void Start()
{
jsEnv = new JsEnv(new DefaultLoader("F:/puerts/unity/TsProj/output/"), 8080);
}
void Update()
{
jsEnv.Tick();
}
async void RunScript()
{
jsEnv = new JsEnv(new DefaultLoader("E:/puerts_unity_demo/TsProj/output/"), 8080);
await jsEnv.WaitDebuggerAsync();
jsEnv.Eval("require('QuickStart')");
}
void Start()
{
RunScript();
}
void Update()
{
jsEnv.Tick();
}
** Example of synchronous blocking waiting
void Start()
{
jsEnv = new JsEnv(new DefaultLoader("E:/puerts_unity_demo/TsProj/output/"), 8080);
jsEnv.WaitDebugger();
jsEnv.Eval("require('QuickStart')");
}
void Update()
{
jsEnv.Tick();
}
In VSCode, open the setting, search for "auto attach", and set "Debug>Node:Auto Attach" to "on" (this option may not exist in higher versions of VSCode and can be left unset).
Or cereate a launch.json to attach it manually:
Open the "ProjectSetting/Player" page and check "Run In Background".