0

I have 2 buttons to load the different texture images and when i press the 1st it loads the 4 images in textures and when i press the 2nd button it loads the 3 images in textures. But the problem is when i press the 1st button it loads the 4 images and when i press the 2nd it loads the images but it starting from 5th place. I can't reset the value to 0 when i press the second button.

 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;

            }

when i press the 1st button and the clone value passing to 0. So, the texture image properly loading in the 0th position but when i press the second button the clonevalue passing to number 5. so, the texture image displaying in the 5th place. So, how can i reset the clonevalue 0 when i press the 2nd button. So, that i can easily pass to 0.

raj
  • 17
  • 9
  • put all the code above into a method, and make your "clonevalue" variable local, so everytime the method is called, "clonevalue" will start at 0. – Venkat at Axiom Studios Jan 06 '15 at 08:19
  • I didn't understand the line, put all the code above into a method and do i need to to put the i also as local variable..because if i increase then the clonevalue also increase – raj Jan 06 '15 at 08:31
  • If i use local variable and all the texture images are displaying at the 0th position only, it's not showing as one by one or for scrolling – raj Jan 06 '15 at 08:40
  • parameterize the method to take an integer to loop a certain number of times. Example public void SomeMethod (int loops) { for(int i = 0; i < loops; i++) { //Do stuff here } } Call the method with a parameter of 4 for the first button and 3 for the second – Venkat at Axiom Studios Jan 06 '15 at 08:43
  • it's not static 4..the textures are fetching from server json url and displaying and it would be vary depend on user upload in the backend.. For example, i have 5 categorys like 1,2,3,4,5 and each category has some images to load in the textures...in the first i'm displaying category list and click any of the category then i'm getting the category_id and loading that category images from json url – raj Jan 06 '15 at 09:07

0 Answers0