Advertisement
fivearchers

Screenshot Script for Unity

Feb 4th, 2014
224
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Screenshot : MonoBehaviour {
  5.    
  6.     public string prefname="LastScreenshotNumber";
  7.     public string screenshotprefix;
  8.     public string screenshotsuffix;
  9.     public int startAtShot=100;
  10.     public float ssDelay=1f;
  11.     public KeyCode ssKey=KeyCode.F2;
  12.     float nextSSAt;
  13.    
  14.     // Use this for initialization
  15.     void Start () {
  16.         if (!PlayerPrefs.HasKey(prefname)){
  17.             PlayerPrefs.SetInt(prefname,startAtShot);  
  18.         }
  19.     }
  20.    
  21.     // Update is called once per frame
  22.     void Update () {
  23.         if (Input.GetKey(ssKey)&&Time.timeSinceLevelLoad>=nextSSAt){
  24.             int cshotn=PlayerPrefs.GetInt(prefname);
  25.             cshotn++;
  26.             string ssname=Application.dataPath+"/"+screenshotprefix+cshotn.ToString()+screenshotsuffix+".png";
  27.             Debug.Log ("Taking screenshot "+ssname);
  28.             Application.CaptureScreenshot( ssname);
  29.             PlayerPrefs.SetInt(prefname,cshotn);
  30.             nextSSAt=Time.timeSinceLevelLoad+ssDelay;
  31.         }
  32.     }
  33. }
Advertisement
RAW Paste Data Copied
Advertisement