I am trying to fetch a image texture from
IEnumerator GetRequest1(string uri)
{
using (UnityWebRequest webRequest = UnityWebRequest.Get(uri))
{
yield return webRequest.SendWebRequest();
img = ((DownloadHandlerTexture)webRequest.downloadHandler).texture;
}
}
and passing it to a GUI
void OnGUI()
{
GUILayout.BeginArea(new Rect(100, 50, 500, 500));
GUILayout.Label(img);
GUILayout.EndArea();
}
on it should have worked previous days it was, today with some modifications its hitting error ,tried this and much more, but could not get helped. It would be great if I get a hint. thank you
i am using same method somewere else but thats perfect , in here its hitting error as
InvalidCastException: Specified cast is not valid. gettiles+d__25.MoveNext () (at Assets/Scripts/gettiles.cs:111)UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Scripting/Coroutines.cs:17)
an InvalidCastException error Hits in case where the actual type of the data doesn't match the type which was passed But here it is sprite to sprite
specificimage.sprite = Sprite.Create(((DownloadHandlerTexture)webRequest.downloadHandler).texture, new Rect(0, 0, 250,250).texture.height), new Vector2(0.5f, 0.5f));
UnityWebRequest request = UnityWebRequestTexture.GetTexture(url)
– Mohammed Sajid