【发布时间】:2020-07-29 21:35:46
【问题描述】:
我是 Unity 新手,我现在面临一个问题,即显示上一个屏幕截图而不是当前屏幕截图。
我的代码: 截图
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TakeScreenshot : MonoBehaviour
{
IEnumerator CaptureIt()
{
ScreenCapture.CaptureScreenshot("*.png", 0);
yield return new WaitForEndOfFrame();
yield return new WaitForSecondsRealtime(1.5f);
}
public void TakeAShot()
{
StartCoroutine(CaptureIt());
}
}
截图展示
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.IO;
public class ScreenshotPreview : MonoBehaviour
{
[SerializeField]
GameObject canvas;
// Use this for initialization
void Start()
{
string url = Application.persistentDataPath + "/" + "*.png";
var bytes = File.ReadAllBytes(url);
Texture2D texture = new Texture2D(2, 2);
bool imageLoadSuccess = texture.LoadImage(bytes);
while (!imageLoadSuccess)
{
print("image load failed");
bytes = File.ReadAllBytes(url);
imageLoadSuccess = texture.LoadImage(bytes);
}
print("Image load success: " + imageLoadSuccess);
canvas.GetComponent<Image>().overrideSprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0f, 0f), 100f);
}
}
有没有人可以帮助我解决这个问题?
【问题讨论】:
标签: unity3d