public void GetNextPipe(int clickedX, int clickedY, Image img, SingleGrid g) { // ridObjs[clickedX + width*clickedY].GetComponent<Image>().sprite img.sprite = nextT.GetChild(nextT.childCount - 1).GetComponent <Image>().sprite; img.material.SetTexture("_GradientTex", nextT.GetChild(nextT.childCount - 1).GetComponent <Image>().material.GetTexture("_GradientTex")); g.SetLogic((int)nextT.GetChild(nextT.childCount - 1).GetComponent <SingleGrid>().currentPipe); for (int i = 0; i < nextT.GetChild(nextT.childCount - 1).GetComponent <SingleGrid>().numOfRotations; i++) { g.RotatePipe(); } Destroy(nextT.GetChild(nextT.childCount - 1).gameObject); // nextObjs.RemoveAt(nextObjs.Count - 1); // Add one to end, change it to start and change rest to +1 GameObject newGridObj = Instantiate(gridObj, nextT); gridBlocks.Add(newGridObj.GetComponent <SingleGrid>()); // nextObjs.Add(newGridObj); int random = Random.Range(0, pipes.Length); newGridObj.GetComponent <Image>().sprite = pipes[random]; newGridObj.GetComponent <Image>().material.SetTexture("_GradientTex", pipeGradients[random]); newGridObj.GetComponent <SingleGrid>().SetLogic(random); int randRot = Random.Range(0, 4); for (int j = 0; j < randRot; j++) { newGridObj.GetComponent <SingleGrid>().RotatePipe(); } newGridObj.GetComponent <SingleGrid>().numOfRotations = randRot; nextT.GetChild(nextT.childCount - 1).transform.SetAsFirstSibling(); // GameObject firstObj = nextObjs[0]; // // nextObjs[0] = nextObjs[nextObjs.Count-1]; // for(int i = 0; i < nextObjs.Count-1; i++) // { // nextObjs[i] = nextObjs[i+1]; // } // nextObjs[0] = firstObj; }