Hello!
I have a list of objects (Texture2D and Texture) and I want to use the Texture 2D objects as sprites on a GUI image.
How can I cast the objects from the list that are Texture2D as sprite?
So far I’ve got this but the sprite field in the image stays empty… :
foreach (Object obj in objectList) {
System.Type type = obj.GetType();
if (type == typeof(UnityEngine.Texture2D)) {
Image newImage = (GalleryImage)Instantiate(imagePrefab);
newImage.sprite = obj as Sprite;
}
}
Can you help please?