Created
March 23, 2019 14:21
-
-
Save huihut/d6815f494298ae8de19fbc31fe137f54 to your computer and use it in GitHub Desktop.
Unity TakeScreenshot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class Screenshot : MonoBehaviour | |
{ | |
private int index = 0; | |
// Start is called before the first frame update | |
void Start() | |
{ | |
} | |
// Update is called once per frame | |
void Update() | |
{ | |
} | |
public void OnScreenshotButton() | |
{ | |
StartCoroutine(CaptureScreen()); | |
} | |
private IEnumerator CaptureScreen() | |
{ | |
// Wait till the last possible moment before screen rendering to hide the UI | |
yield return null; | |
GameObject.Find("Canvas").GetComponent<Canvas>().enabled = false; | |
// Wait for screen rendering to complete | |
yield return new WaitForEndOfFrame(); | |
index++; | |
// Take screenshot | |
ScreenCapture.CaptureScreenshot(@"screenshot" + index.ToString("D3") + ".png"); | |
// Show UI after we're done | |
GameObject.Find("Canvas").GetComponent<Canvas>().enabled = true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment