Hello, I have searched the net and fora for a small script that takes a screenshot of your screen. what i want: target is iOS and Android mobile devices. in my UI i have made a button with a camera picture. the idea is that when the button is pressed a screenshot is taken and preferable saved in the screenshots or images folder on the device. like the 2 button pressing (home + volume for instance) but this function i would like in my button. Is this possible? i have searched for scripts and used these 3 below. none of them work on both iOS and Android. I use unity 4.6.1 pro and the devices tested on are the Ipad air,Iphone 6, IPhone 6+,IPhone 4s, Samsung s5, Samsung tab 3. I am looking for a script that makes a screenshot with the void onMouseDown () and then works on both iOS and Android. Preferably not a plugin, just the script. Thanx in advance. Nick Lourens none of the scripts below do anything. what am i doing wrong? SCRIPT 1 using UnityEngine; using System.Collections; public class showscreenshot : MonoBehaviour { void OnMouseDown() { Application.CaptureScreenshot("Screenshot.png"); } } SCRIPT 2 using UnityEngine; using System.Collections; public class showscreenshot2 : MonoBehaviour { private int screenshotCount = 0; // Check for screenshot key each frame void Update() { // take screenshot on touch if (Input.touches.Length > 1) { string screenshotFilename; do { screenshotCount++; screenshotFilename = "screenshot" + screenshotCount + ".png"; } while (System.IO.File.Exists(screenshotFilename)); // audio.Play(); Application.CaptureScreenshot(screenshotFilename); } } } SCRIPT 3 using UnityEngine; using System.Collections; public class showscreenshot3 : MonoBehaviour { void OnGUI() { if (GUI.Button (new Rect(50,550,250,100), "Capture")) { string filename = "shot.png"; Application.CaptureScreenshot(filename); if (QCARRuntimeUtilities.IsPlayMode()) { // if in PlayMode, the screenshot will be saved // to the project directory Debug.Log ("Saved screenshot to " + filename); } else { // if running on Device, the screenshot will be saved // to the Application.persistentDataPath directory Debug.Log ("Saved screenshot to " + Application.persistentDataPath + "/" + filename); } } } }
The first script should work just fine - it's supposed to save the image to the 'Documents' folder, I don't know exactly this will be on iOS, but it's supposed to work seamlessly. Have you verified that the OnMouseDown() event is firing? This may assist in finding the documents folder location: http://answers.unity3d.com/questions/18647/unity-iphone-can-i-store-data-on-the-iphone-to-be.html
Thnx for the reply i can verify that by adding Debug.Log(button works!!!); right? i will test this anyway. is there maybe a bug with iphone 6+ and unity 4.6.1 with the capture? the first script does not return the picture in the picture gallery. i will try to find it manually. *update* debug.log returns in the console. so button is working
This does not save it to the gallery, for that you'll need to use native calls to iOS. There are a few plugins to do this: http://u3d.as/content/devesh-pandey/capture-and-save/86U https://www.assetstore.unity3d.com/en/#!/content/7827 This free one I think can do it also: https://www.assetstore.unity3d.com/en/#!/content/9555 Or you could make you're own plugin (iOS plugins are typically easy to write).