Jump to content
Unity Insider Forum
Sign in to follow this  
Kojote

Screenshot Snippet

Recommended Posts

Grüße!

Hier mal ein kleines Screenshot-Snippet für Unity 2017. Viel Spaß damit! :) 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;

public class Screenshots : MonoBehaviour {

    private Canvas canvas;

    public KeyCode screenshotKey = KeyCode.F8; // Auswahl Key-Taste für Screenshot

    public string gamename = "Gamename"; // Name des Spiels
    private string path;

    public bool canvasShow = false; // Screenshots mit oder ohne GUI


    private void Awake() {
        canvas = GameObject.Find("Canvas").GetComponent<Canvas>();
        path = Application.dataPath + "/Screenshots";
        if (!Directory.Exists(path)) {
            Directory.CreateDirectory(path);
        }
    }

    private void LateUpdate() {
        if (Input.GetKeyDown(screenshotKey)) {
            StartCoroutine(RecordFrame());
        }
    }

    IEnumerator RecordFrame() {
        if(!canvasShow)
        canvas.enabled = false;

        string time = System.DateTime.Now.ToString("dd-MM-yyyy_HH-mm-ss");

        yield return new WaitForEndOfFrame();

        ScreenCapture.CaptureScreenshot(path + "/" + name + "_" + time + ".png", 0);

        if (!canvasShow)
        canvas.enabled = true;

        yield return new WaitForSeconds(1.0f);
    }
}

Kojote

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×