Search Unity

Screenshot Mobile devices

Discussion in 'Scripting' started by Clownfish CC, Apr 2, 2015.

  1. Clownfish CC

    Clownfish CC

    Joined:
    Apr 1, 2015
    Posts:
    13
    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);
    }
    }
    }
    }

     
  2. Clownfish CC

    Clownfish CC

    Joined:
    Apr 1, 2015
    Posts:
    13
    anyone can help me with this pls :)
     
  3. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422
  4. Clownfish CC

    Clownfish CC

    Joined:
    Apr 1, 2015
    Posts:
    13
    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
     
    Last edited: Apr 7, 2015
  5. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422
  6. Clownfish CC

    Clownfish CC

    Joined:
    Apr 1, 2015
    Posts:
    13
    thnx for your reply. i will look into it :)