Unity 3D Game Engine – Get Screenshot – Android

How to get a in-game Screenshot with Unity 3D – UNTESTED

IMPORTANT!!!

Unity> MAIN TOP MENU> File> Build Settings> Player Settings…> Other Settings> Configuration> Write Access> External (SD Card), this setup will create inside Android Device using Windows 7 -> Phone/Android/data/com.Company.LuceDigitale

It this equal the write inside AndroidManifest.xml ->

Method 1

Application.CaptureScreenshot

NOTICE: CaptureScreenshot is asynchronous. This is because capturing and saving the screen can take awhile.

Inside Hierarchy create a structure with:

1. Some Objects

2. Main Camera, attach the script ‘GetScreenShot.js’

GetScreenShot.js


#pragma strict

// For Android Devices ONLY
// Attach this script to Main Camera

// File> Build Settings> Player Settings...> Other Settings> Configuration> Write Access> External (SD Card),
// this setup will create inside Android Device using Windows 7 -> Phone/Android/data/com.Company.LuceDigitale
// It this equal the write inside AndroidManifest.xml ->  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

var scoreTextX : GUIText;
var localize   : String;

function Start() {
}

function OnGUI()
{
  if (GUI.Button(Rect(10,10,200,50),"Capture Screenshot"))
  { 
    // debug data path
    localize = Application.persistentDataPath;
    scoreTextX.text = localize;
    // it writes:  /storage/sdcard0/Android/data/<bundle id>/files folder
    
    // We should only read the screen buffer after rendering is complete
    yield WaitForEndOfFrame();
    
    // Application.dataPath DOES NOT have write permission on Android, you need Application.persistentDataPath
    // static function CaptureScreenshot(filename: string, superSize: int = 0): void;
    Application.CaptureScreenshot("Screenshot.png");
    // the file will be saved on: /storage/sdcard0/Android/data/<bundle id>/files folder
  }
}