My code strangely isn't loading the user images from local hard drive to the gameObject called "planeLogo". The file with the function ImageUploaderCaptureClick() is called ImageUploader1.jslib and resides in the plugins/WebGl folder.
Here's the script
using UnityEngine;
using System.Collections;
using System.Runtime.InteropServices;
public class LoadImage : MonoBehaviour
{
[DllImport("__Internal")]
private static extern void ImageUploaderCaptureClick();
private Texture2D displayedTexture;
IEnumerator LoadTexture(string url)
{
WWW image = new WWW(url);
yield return image;
image.LoadImageIntoTexture(displayedTexture);
}
void FileSelected(string url)
{
StartCoroutine(LoadTexture(url));
}
public void OnButtonPointerDown()
{
#if UNITY_EDITOR
string path = UnityEditor.EditorUtility.OpenFilePanel("Open image", "", "jpg,png,bmp");
if (!System.String.IsNullOrEmpty(path))
FileSelected("file:///" + path);
#else
ImageUploaderCaptureClick ();
#endif
}
void Start()
{
displayedTexture = new Texture2D(1, 1);
GameObject.Find("PlaneLogo").GetComponent<MeshRenderer>().material.mainTexture = displayedTexture;
GameObject.Find("PlaneLogo").GetComponent<Renderer>().enabled = true;
}
}
And here's how I deal with the events.
I've tried everything I know and the project keeps working inside Unity but does not when it's compiled as html(webgl).