如何调试?
配置调试
- 打开 Unity 编辑器
可在后台
运行选项- 勾选 File -> Build Settings -> Player -> Resolution and Presentation -> Run In Background*
- 项目根目录下创建
.vscode/launch.json
.vscode/launch.json
内容如下(切记端口要与 Unity 中设置一至):
{
"version": "0.2.0",
"configurations": [{
"name": "Puerts Debug",
"type": "node",
"request": "attach",
"protocol": "inspector",
"port": 43990
}]
}
启用调试
- Unity打开
Assets/Sceneces/Main.unity
场景 - Hierarchy -> 选中 Main -> Inspector -> 勾选 Is Debug
- 运行游戏,此时 Unity 引擎将处于卡死等待连接状态
- vscode -> Side面板 -> 运行和调试(点击虫子 Icon打开面板)-> 点击 Puerts Debug 前方的小箭头连接