索引值数组不是从0开始

时间:2015-01-06 08:07:59

标签: arrays unity3d clone gameobject

我有2个按钮来加载不同的纹理图像,当我按下第一个时,它会在纹理中加载4个图像,当我按下第二个按钮时,它会在纹理中加载3个图像。但问题是,当我按下第一个按钮时,它会加载4个图像,当我按下第二个按钮时,它会加载图像但是从第5个位置开始。当我按下第二个按钮时,我无法将值重置为0.

 private int clonevalue = 0;
     public int i = 0;


 string response = www.text;
        IDictionary search = (IDictionary) Json.Deserialize(response);

        IList linksObject = (IList) search["Products"];  //Here searching only products array


        foreach (IDictionary modellinksArray in linksObject) {



            string cat_id=string.Format("{0} ", modellinksArray["category_id"]);   //From products array getting the category_id
            //int catd_id_int = int.Parse(cat_id);  //Converting the string value to integer



            if(cat_id == myId){//Now, i have used static code value of 4 and if the value match and we can gets only matching category model. Here you can pass the id value of category list selected.

                int clonevalue = 0;
                int i = 0;

                // i = 0;
                cloneGO = Instantiate(myScrollTexture)as GameObject;
                cloneGO.transform.parent = parentObject.transform;
                cloneGO.transform.localPosition =new Vector3(127,30,0);
                cloneGO.transform.localScale =Vector3.one;
                cloneGO.name = "cloneScrollTexture"+i;

                string myTexture = string.Format("{0} ", modellinksArray["imageurl"]);
                string modelUrl = string.Format("{0} ", modellinksArray["modelurl"]);
                i++;
                //StartCoroutine(Load3D(modal3d,modal3d));

                cloneGO.GetComponent<dynamicmodelload>().modelURL = modelUrl;


                //Destroy(cloneGO);

                WWW www1 = new WWW(myTexture);
                Debug.Log("text"+myTexture);

                yield return www1;

                //if(!www1.isDone){
                    //yield return null;  
                //}
                //if(www1.isDone){
                    Debug.Log (clonevalue);
                    //clonevalue = 0;
                    //DebugConsole.Log (clonevalue);

                    myTextureObject = GameObject.Find ("cloneScrollTexture" + clonevalue);
                    //Debug.Log (myTextureObject);
                    clonevalue++;
                    Debug.Log (myTexture);
                    myTextureObject.GetComponent<UITexture>().mainTexture = www1.texture;
                    Debug.Log ("myTextureObject"+myTexture);
                    //DebugConsole.Log ("myTextureObject"+myTexture);


                    if (myTextureObject.name == "cloneScrollTexture"+evenValues) {
                        myTextureObject.transform.localPosition =new Vector3(-81,30,0);
                        evenValues +=2;
                        Debug.Log (evenValues);
                        //DebugConsole.Log (evenValues);
                    }

                    if(myTextureObject.name == "cloneScrollTexture"+yevenValue){
                        yValue += 210;
                        Debug.Log("yevenValue"+yevenValue);
                        //DebugConsole.Log("yevenValue"+yevenValue);
                        yevenValue +=2;

                    }
                    //for(int i=0; i< 2; i++){
                    Debug.Log ("yValue"+yValue);
                    //DebugConsole.Log ("yValue"+yValue);
                    myTextureObject.transform.localPosition -=new Vector3(0,yValue,0);
                    Debug.Log ("myTextureObject"+myTextureObject.transform.localPosition);
                    //evenValues +=2;
                    //  test = 5;

            }

当我按下第一个按钮并且克隆值传递到0.因此,纹理图像正确加载到第0个位置但是当我按下第二个按钮时克隆值传递到数字5.所以,纹理图像显示在第五名。那么,当我按下第二个按钮时,如何重置克隆值0。所以,我可以很容易地传到0。

0 个答案:

没有答案