Can you help me spotting the error? if I do:
private Image ImgPreview;
private Text TxtBrand, TxtProduct, TxtDimentions, TxtDescription, TxtPrice;
// Use this for initialization
void Start () {
ImgPreview = transform.GetChild(0).GetComponent<Image>();
TxtProduct = transform.GetChild(1).GetComponent<Text>();
TxtBrand = transform.GetChild(2).GetComponent<Text>();
TxtDimentions = transform.GetChild(3).GetComponent<Text>();
TxtDescription = transform.GetChild(4).GetComponent<Text>();
TxtPrice = transform.GetChild(5).GetComponent<Text>();
TxtProduct.text = "test";
}
My routine works fine, but if i do:
private Image ImgPreview;
private Text TxtBrand, TxtProduct, TxtDimentions, TxtDescription, TxtPrice;
// Use this for initialization
void Start () {
ImgPreview = transform.GetChild(0).GetComponent<Image>();
TxtProduct = transform.GetChild(1).GetComponent<Text>();
TxtBrand = transform.GetChild(2).GetComponent<Text>();
TxtDimentions = transform.GetChild(3).GetComponent<Text>();
TxtDescription = transform.GetChild(4).GetComponent<Text>();
TxtPrice = transform.GetChild(5).GetComponent<Text>();
}
private IEnumerator GetLogo(string url, int version)
{
TxtProduct.text = "test";
WWW www = new WWW(url);
yield return www;
ImgPreview.sprite = Sprite.Create(www.texture, new Rect(0, 0, www.texture.width, www.texture.height), new Vector2(0, 0));
}
I get the following Error:
NullReferenceException: Object reference not set to an instance of an object ProductBtn.SetInfo (Int32 id, System.String product, System.String category, System.String brand, System.String url, System.String price, System.String coin, System.String width, System.String height, System.String depth, System.String assetobj, System.String assetname, System.String thumbnail, Int32 thumbnailver) (at Assets/Scenes/Product/Scripts/ProductBtn.cs:62) ProductControl+c__Iterator0.MoveNext () (at Assets/Scenes/Product/Scripts/ProductControl.cs:45) UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)
--- Edit --- After making some tests i realized that changing my text from "private" to "public" fixes the error, can somebody explain to me why? i cannot understand the reason
thanks...