Hello everyone!
I’m trying to dynamically change a RawImage
Here’s my code bellow, doesn’t seem to work
Can’t find anything online
I should also add that I’m a new Unity Dev
Thanks in Advance!
{
public RawImage img;
private string url = "https://i.redd.it/bz504sn6ree51.png";
//private int imgHeight = 250;
//private int imgWidth = 250;
//private int posX = 10;
//private int posY = 50;
private int counter = 1;
// Start is called before the first frame update
void Start()
{
StartCoroutine(ChangeImage());
}
IEnumerator ChangeImage(){
yield return 0;
UnityWebRequest www = UnityWebRequestTexture.GetTexture(url);
Debug.Log("Here2, url: "+url);
yield return www.SendWebRequest();
img.texture = DownloadHandlerTexture.GetContent(www);
// TextureScaler.scale(img.texture,imgHeight,imgWidth);
}
void Update()
{
if(Input.GetKeyDown(KeyCode.Space)){
if(counter % 2 == 0){
url = "https://i.redd.it/bz504sn6ree51.png";
}else{
url = "https://i.redd.it/rgce12mplle51.jpg";
}
counter++;
Debug.Log("Here");
StartCoroutine(ChangeImage());
}
}
}