void Update () {
if (Input.GetKeyDown(KeyCode.C))
{
string fileName = DateTime.Now.Ticks.ToString();
string tagerFolder = DateTime.Now.ToString("yyyy-MM-dd");
string pathName = Path.Combine(Application.persistentDataPath, tagerFolder);
if (!Directory.Exists(pathName))
{
Directory.CreateDirectory(pathName);
}
string path = Path.Combine(pathName, fileName + ".png");
//Application.CaptureScreenshot(path);Unity2017弃用了
ScreenCapture.CaptureScreenshot(path);
Debug.Log(path);
}
}如果不写路径只写文件名时,截图就会在保存在Unity工程的根目录中。