I manage to download a texture from the web but I’m unable to apply it as a texture in a material.
I would appreciate to get some help.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Assertions.Must;
using UnityEngine.UI;
public class test : MonoBehaviour {
// public string url = "https://dummyimage.com/500x500/000/fff";
public string url = "https://docs.unity3d.com/uploads/Main/ShadowIntro.png";
public Material MaterialToEdit;
public GameObject sphere;
public GameObject cube;
public GameObject card;
MeshRenderer meshRenderer;
Texture2D texturea;
IEnumerator Start()
{
meshRenderer = GetComponent<MeshRenderer> ();
//start download
var www = new WWW(url);
//wait until download completes
yield return www; // wait for www to return
//create a DXT1 (compressed) texture
texturea = new Texture2D(www.texture.width, www.texture.height, TextureFormat.DXT1, false);
www.LoadImageIntoTexture(texturea);
Rect rect = new Rect(0, 0, texturea.width, texturea.height);
MaterialToEdit.SetTexture ("Mask", texturea);
meshRenderer.material.SetTexture ("Mask", texturea);
// card.renderer.material.Mask = texturea;
// card.material.SetTexture("Mask", texture);
}
}