- Home /
Question by
hollym16 · Jul 07, 2017 at 02:07 PM ·
androidbuttonscreenshotmanifest
Screenshot functionality Android
I am using the script below in an Android project to take a screenshot. In the Editor it works perfectly, but when I push it to an Android device it has an issue. When you first press the button, it does nothing but press it again and it works as intended.
I'm thinking this is something to do with the permission perhaps. I do have "android.permission.WRITE_EXTERNAL_STORAGE" in my AndroidManifest.
Does anyone now whats causing this?
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.IO;
public class ScreenshotAVR : MonoBehaviour {
public bool hideGUI = false;
public Text console;
public CanvasGroup ui;
public CanvasGroup ui2;
public CanvasGroup uiTip;
public Image screenshot;
void Start(){
screenshot.enabled = false;
console.enabled = false;
}
void OnEnable ()
{
// call backs
ScreenshotManager.OnScreenshotTaken += ScreenshotTaken;
ScreenshotManager.OnScreenshotSaved += ScreenshotSaved;
}
void OnDisable ()
{
ScreenshotManager.OnScreenshotTaken -= ScreenshotTaken;
ScreenshotManager.OnScreenshotSaved -= ScreenshotSaved;
}
public void OnSaveScreenshotPress()
{
ScreenshotManager.SaveScreenshot("MyScreenshot", "MyApp", "jpeg");
if(!hideGUI)
ui.alpha = 0f;
ui2.alpha = 0f;
uiTip.alpha = 0f;
screenshot.enabled = true;
screenshot.GetComponent<AudioSource>().Play ();
}
void ScreenshotTaken(Texture2D image)
{
screenshot.sprite = Sprite.Create(image, new Rect(0, 0, image.width, image.height), new Vector2(.5f, .5f));
screenshot.color = Color.white;
console.enabled = true;
ui.alpha = 1f;
ui2.alpha = 1f;
uiTip.alpha = 1f;
StartCoroutine ("Fade");
}
void ScreenshotSaved(string path){
}
IEnumerator Fade(){
yield return new WaitForSeconds (2);
screenshot.enabled = false;
console.enabled = false;
}
}
Comment