playMaker

Author Topic: Attach Script Help![SOLVED]  (Read 2157 times)

nabilfx

  • Full Member
  • ***
  • Posts: 186
Attach Script Help![SOLVED]
« on: April 15, 2014, 10:20:33 AM »
I have this script, and i want to conect it to a GUI button from Playmarker,
I try the SendMessage action and at the MethodName i put the public class name (GalleryScreenshotExample) but does not work, Please any help?
The script that i want to attach to the GUIButton is bellow.

Code: [Select]
using UnityEngine;
using System.Collections;
using System.IO;

public class GalleryScreenshotExample : MonoBehaviour {

public Texture2D texture;
// bool saved = false;
// bool saved2 = false;

void Start ()
{
ScreenshotManager.ScreenshotFinishedSaving += ScreenshotSaved;
ScreenshotManager.ImageFinishedSaving += ImageSaved;
}

void OnGUI ()
{
// GUILayout.Label("Example scene showing: \n1. how to save a screenshot\n" +
// "2. how to save an image from your assets");

if(GUILayout.Button ("Take Screenshot", GUILayout.Width (200), GUILayout.Height(80)))
{
StartCoroutine(ScreenshotManager.Save("MyScreenshot", "MyApp", true));
}

// if(saved) GUILayout.Label ("Screenshot was successfully saved");

// GUILayout.Space(40);
//
// GUILayout.Label(texture);
//
// if(GUILayout.Button ("Save " + texture.name, GUILayout.Width (200), GUILayout.Height(80)))
// {
// StartCoroutine("SaveAssetImage");
// }
//
// if(saved2) GUILayout.Label(texture.name + " was successfully saved");
}

IEnumerator SaveAssetImage ()
{
byte[] bytes = texture.EncodeToPNG();
string path = Application.persistentDataPath + "/MyImage.png";
File.WriteAllBytes(path, bytes);

yield return new WaitForEndOfFrame();

StartCoroutine(ScreenshotManager.SaveExisting(path, true));
}

void ScreenshotSaved()
{
Debug.Log ("screenshot finished saving");
// saved = true;
}

void ImageSaved()
{
// Debug.Log (texture.name + " finished saving");
// saved2 = true;
}
}
« Last Edit: April 17, 2014, 02:44:06 PM by jeanfabre »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Attach Script Help!
« Reply #1 on: April 15, 2014, 10:45:40 AM »
Hi,

 your methods MUST be public too, so add the word "public" before your method signature, then it will become visible.

bye,

 Jean

nabilfx

  • Full Member
  • ***
  • Posts: 186
Re: Attach Script Help!
« Reply #2 on: April 15, 2014, 02:20:20 PM »
Where do i put this word public?
Attach is the GuiButton and the SendMessage to call the script image.
« Last Edit: April 15, 2014, 04:42:35 PM by nabilfx »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Attach Script Help!
« Reply #3 on: April 17, 2014, 02:16:03 PM »
Hi,

 in "galleryScreenShotExample" script itself, on the method you want to call like this:

Code: [Select]
public void ScreenshotSaved()
Also, if you plan on calling "SaveAssetImage", then you may have a problem with "IEnumerator" and so you should create another public method for instance "SaveImage" that in turn call "SaveAssetImage", then, you'll be ok.


 also, the send message action must reference the method you want to call, not the script class name.


try using "invoke" action, this may be easier for you to grasp ( but "public" methods are also required, as invoke can only access public methods too).

bye,

 Jean

nabilfx

  • Full Member
  • ***
  • Posts: 186
Re: Attach Script Help!
« Reply #4 on: April 17, 2014, 02:32:03 PM »
Thanks it works!!!