I have a screenshot preview at the end of the game’s level.
When I am loading the screenshot, it makes game freeze for a moment.
What shall I do, so there would be no freeze, when I am loading that screenshot?
Here is mycode:
private IEnumerator ShowScreeshotPreview()
{
screenshotTexture = new Texture2D(Screen.height, Screen.height, TextureFormat.RGB24, false);
for (int i = 0; i < 9; i++)
{
yield return null;
}
RenderTexture.active = Singletons.Get<SpecialEffectsHelper>().MainCharacterScript.GetComponent<GeneratorScript>().screenshotTexture;
screenshotTexture.ReadPixels(new Rect(0, 0, Screen.height, Screen.height), 0, 0);
screenshotTexture.Apply();
RenderTexture.active = null; //Added to avoid errors
screenshotPrview.mainTexture = screenshotTexture;
ScreenshotPreviewAnimator.SetBool("visible", true);
screenshotLoaded = true;
yield return null;
}