- Home /
Javascript command for taking a screenshot then saving it to a folder directory??
My question is basically what the title is, I'm new to Unity and learning Javascript. All help will be appreciated. for iOS platform
Don't use titles as the actual question, it's messy. Take the time to write it properly in the post.
Answer by syclamoth · Oct 19, 2011 at 01:06 PM
Funnily enough, if you'd searched for 'screenshot' in the unity scripting reference, this would have been the first hit. Use the API reference! It's there to help you.
I have the script for the screenshot itself, but I want to run it on my iOS Device and save it to the Photo library. I'm unsure on what the commands are to put the image take to the directory - private/var/root/$$anonymous$$edia/DCI$$anonymous$$/100APPLE (or ~/$$anonymous$$edia/DCI$$anonymous$$/100APPLE)
Well then I take it back. Could you please clarify your question so that it's obvious that you're talking about iOS here? It's kind of more complicated, then.
I could be wrong, but I think you need to write native code to achieve this. I'm pretty sure you're only allowed to write to a specific directory on iOS devices.
If I am wrong (and this can be done in Unity) I'd love to know how!
Answer by r31s · Oct 19, 2011 at 02:13 PM
// The folder we place all screenshots inside.
// If the folder exists we will append numbers to create an empty folder.
var folder = "ScreenshotFolder";
private var realFolder = "";
function OnGUI () {
if (GUI.Button (Rect (10,10, 100, 50),"take screenshot")) {
captureScreen();
}
}
function Start () {
// Find a folder that doesn't exist yet by appending numbers!
realFolder = folder;
count = 1;
while (System.IO.Directory.Exists(realFolder)) {
realFolder = folder + count;
count++;
}
// Create the folder
System.IO.Directory.CreateDirectory(realFolder);
}
function captureScreen () {
// name is "realFolder/0005 shot.png"
var name = String.Format("{0}/{1:D04} shot.png", realFolder, Time.frameCount );
// Capture the screenshot
print("Screenshot taken");
Application.CaptureScreenshot (name);
}
I'm using this script to try and link up onGUI to capture screenshot function so that on the iOS images are saved to the photo library.
Hope this makes more sense as to my problem.
Format your code with the little 0101 button when writing your post(or editing). That will help other read your code
Hey there, very interested as to whether you've been able to get this working?
I'm almost positive that it is NOT possible to write to the Camera Roll without writing your own native code. That means you have to write Objective C code.
There are only a couple directories that are accessible from within Unity. The Camera Roll folder is not one of them.
This question has been asked many many times. I've ready many forum posts and Unity Answers questions on the subject. I've never seen anybody offer a way to do it without using Objective C.
Notice that I made the same comment back in October and it was up-voted.
Answer by r31s · Feb 18, 2012 at 03:01 PM
Yes we did manage to get it working siberman, jahroy is right that it implies native code, great plugin worth investing in is prime 31 plugins as it does everything you need plus extra things too, there support is quick responce too.
Hope this helps. Reis.
Your answer
Follow this Question
Related Questions
Automatically load asset bundles on start from cache 0 Answers
A node in a childnode? 1 Answer
Make an object move in the direction of touch 0 Answers
how do you make an object rotate on ios with your finger 3 Answers
Unity Push notification 0 Answers