Attach below script to any object in your game. Click Play in editor and at the desired point, press "z" in keyboard to take your screenshot as a png file (if game is built, use Ctrl-Z). The screenshot will be stored (ie; the save location) in your Unity project's root folder
Tip: If you want a specific resolution of screenshot, make sure to set this in the player (ie; in Game tab)
In the below example, we are setting resolution to 2400 x 1200. When you use above script, the saved screenshot will have the same resolution.
See example below. Use + symbol to add custom resolutions
using System.Collections; using System.Collections.Generic; using UnityEngine; public class TakeScreenShot : MonoBehaviour { // Update is called once per frame void Update () { #if UNITY_EDITOR if (Input.GetKey(KeyCode.Z)) #else if((Input.GetKey(KeyCode.RightControl) || Input.GetKey(KeyCode.LeftControl)) && Input.GetKeyDown(KeyCode.Z)) #endif { Debug.Log("Taking screenshot"); ScreenCapture.CaptureScreenshot("ScreenShot-" + UnityEngine.SceneManagement.SceneManager.GetActiveScene().name + ".png"); Debug.Log("Done"); } } }
Tip: If you want a specific resolution of screenshot, make sure to set this in the player (ie; in Game tab)
In the below example, we are setting resolution to 2400 x 1200. When you use above script, the saved screenshot will have the same resolution.
See example below. Use + symbol to add custom resolutions
No comments:
Post a Comment