I'm trying to have a Unity program where I have 5 UI objects and 3 3D objects and take their texture in the script and generate a new texture file with all those and then assign that texture to the objects. I have my 3D objects change texture upon command but they just turn white and my UI objects don't change at all
using UnityEngine;
using System.Collections;
public class texture : MonoBehaviour {
public GameObject[] gameObjects;
public Texture2D[] textures = new Texture2D[8];
void Start () {
}
// Update is called once per frame
void Update () {
}
public void ChangeTex()
{
Texture2D ctex = new Texture2D (800, 200);
for(int i = 0; i < 8; i++)
{
for(int x = 0; x < textures[i].width; x++)
{
for(int y = 0; y < textures[i].height; y++)
{
ctex.SetPixel(x + (100 * i), y, textures[i].GetPixel (x, y));
}
}
}
foreach (GameObject g in gameObjects) {
g.GetComponent<Renderer>().material.mainTexture = ctex;
}
}
}
Do I need to add a certain type of component to my UI objects or is there a problem with my codes logic?