TakeScreenshot

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
m (Minor tweak to match naming conventions in other wiki scripts.)
(C# - TakeScreenshot.cs)
Line 15: Line 15:
 
// work, and Unity doesn't have a mechanism to return special paths. Therefore, the correct way to
 
// work, and Unity doesn't have a mechanism to return special paths. Therefore, the correct way to
 
// solve this is probably with a plug-in to return OS specific special paths.
 
// solve this is probably with a plug-in to return OS specific special paths.
 +
 +
// Mono/.NET has functions to get special paths... see discussion page. --~~~~
  
 
using UnityEngine;
 
using UnityEngine;

Revision as of 09:33, 14 August 2006

Description

Captures sequentially numbered screenshots when a function key is pressed. Existing screenshots are not overwritten.

Usage

Just attach this script to an empty game object.

C# - TakeScreenshot.cs

<csharp>// TODO: // By default, screenshot files are placed next to the executable bundle -- we don't want this in a // shipping game, as it will fail if the user doesn't have write access to the Applications folder. // Instead we should place the screenshots on the user's desktop. However, the ~/ notation doesn't // work, and Unity doesn't have a mechanism to return special paths. Therefore, the correct way to // solve this is probably with a plug-in to return OS specific special paths.

// Mono/.NET has functions to get special paths... see discussion page. --~~~~

using UnityEngine; using System.Collections;

public class TakeScreenshot : MonoBehaviour {

   private int screenshotCount = 0;
       
   // Check for screenshot key each frame
   void Update()
   {
       // take screenshot on up->down transition of F9 key
       if (Input.GetKeyDown("f9"))
       {        
           string screenshotFilename;
           do
           {
               screenshotCount++;
               screenshotFilename = "screenshot" + screenshotCount + ".png";
           } while (System.IO.File.Exists(screenshotFilename));
           
           Application.CaptureScreenshot(screenshotFilename);
       }
   }

} </csharp>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox