I'm currently trying to edit some code to see if an object in an array has a higher x value than 4 in distance between itself and its previous member. From my code I know that it happens but the texture doesn't change. Any help? Code (csharp): public Texture tester; for(int i = 0; i < arrayLength.Length; i++) { if(arrayLength.Length-1 != null) { transform.position = new Vector3(spawnPosX + random_x * LengthRadius, spawnPosY + random_y * HeightRadius+1.2f, spawnPosZ + random_z * LengthRadius); } platSpwans = arrayLength[i].transform.position; arrayLength[i].transform.position = new Vector3(platSpwans.x + random_x * LengthRadius, platSpwans.y + random_y * HeightRadius+1.25f, platSpwans.z + random_z * LengthRadius); if (i > 1) { if (arrayLength[i].transform.position.x > (arrayLength[i -1].transform.position.x+4)) { arrayLength[i].renderer.material.SetTexture("test", tester ); Debug.Log("true"); } }
I assume arraylength is gameobjects? I would use .GetComponent(Renderer) and place that in the variable like rend Then go rend.material = the new material and make a different material for each of the changes you want.