Downloading web JPG and setting it on material

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 = "";
	public string url = "";	
	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);
		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);


alt text

If I read your question correctly You would need to make a new material. On the Inspector and the texture you downloaded you would drag it on to the Albedo box


Or would you rather it be in code?

You could follow this link.

Instead of using main texture
you could do GetComponent().sharedMaterial =
and you assign it to the material you want.

I’m done losing my hair.
It was my shader that had a texture property name that wasn’t the internal property name, that caused my 100 tests to all fail.

	meshRenderer = GetComponent<MeshRenderer> ();
	meshRenderer.material.SetTexture ("vvxwwx", texturea);