如何使用unity在调用cmd同时还能继续执行unity内的代码
时间: 2024-02-27 09:55:45 浏览: 117
你可以使用C#中的Process类来调用cmd。具体操作如下:
1. 创建ProcessStartInfo对象,设置FileName属性为cmd.exe,Arguments属性为你要执行的cmd命令。
2. 创建Process对象,调用Start()方法启动进程。
3. 调用Process对象的WaitForExit()方法等待cmd命令执行完成。
4. 在等待cmd命令执行的同时,可以继续执行unity内的其他代码。
以下是一个示例代码:
```
using System.Diagnostics;
public class Example : MonoBehaviour
{
void Start()
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "/c dir";
Process process = new Process();
process.StartInfo = startInfo;
process.Start();
// 继续执行unity内的其他代码
// ...
process.WaitForExit();
}
}
```
这样就可以在unity中调用cmd,并且同时执行unity内的其他代码了。
阅读全文
相关推荐


















