I load captcha image from localhost and it loads - i can see it in Sprites renderer in materials.
But it do not effect sprite image at all.
How to load image to sprite ? If i get a texture - try different ways - nothing works. What did i make wrong ?
- Code: Select All Code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class KaptchaGetScript : MonoBehaviour {
// Use this for initialization
private string url = "http://localhost/Kaptcha/captcha.php";
//private string url = "http://localhost/Kaptcha/bg_capcha.png";
private Renderer KAPTCHA;
private Sprite sprt;
private WWW www;
private bool READY = false;
IEnumerator Start () {
//void Start() {
//KAPTCHA = GameObject.Find ("KAPTCHA").GetComponent("Renderer") as Renderer;
www = new WWW(url);
yield return www;
//KAPTCHA = new Renderer ();
Debug.Log(www.texture);
//Renderer renderer = GetComponent<Renderer>();
//KAPTCHA.material.mainTexture = www.texture;
//renderer.material.mainTexture = www.texture;
KAPTCHA = GameObject.Find ("KAPTCHA").GetComponent<Renderer>();
KAPTCHA.material.mainTexture = www.texture;
//KAPTCHA.sprite = Sprite.Create((Texture2D)tex, new Rect(0,0, tex.width,tex.height), Vector2.zero);
//sprt = GameObject.Find ("KAPTCHA").GetComponent<SpriteRenderer>().sprite;
//GameObject.Find("111").GetComponent<SpriteRenderer>().sprite = Resources.Load<Sprite>("Sprites/222");
// sprt = Sprite.Create(www.texture, new Rect(0.0f,0.0f,www.texture.width,www.texture.height), new Vector2(0.5f,0.5f), 100.0f);
//sprt = Sprite.Create(www.texture, new Rect(0.0f,0.0f,www.texture.width,www.texture.height), new Vector2(0.5f,0.5f), 100.0f);
//KAPTCHA.Applay ();
www.Dispose();
// www.LoadImageIntoTexture(KAPTCHA.material.mainTexture as Texture2D);
}
// Update is called once per frame
void Update () {
/*
if (READY == false) {
if (www.isDone) {
KAPTCHA.material.mainTexture = www.texture;
READY = true;
}
}
*/
}
}