I am pooling my objects and want to each object to have a new random texture from textures folder, a prefab has a sprite renderer on it and here is my code
Texture2D texture;
private Object[] textures;
void Start () {
textures = Resources.LoadAll("Textures", typeof(Texture2D));
InvokeRepeating("Create", hTime, hTime);
}
void Create()
{
GameObject obj = Pooler.current.GetPooledObject();
if (obj == null) return;
texture = (Texture2D)textures[Random.Range(0, textures.Length)];
obj.GetComponent<Renderer>().material.mainTexture = texture;
obj.transform.position = pos.position;
obj.transform.rotation = transform.rotation;
obj.SetActive(true);
}
}
However it doesn’t work despite of the right hierarchy of my folders.