How to use Resources.LoadAll + OnGUI + Textures?

All… I have wrestled with this problem for a week now.

The following code does not work and gives this error:
Ambiguous reference’Button’

// Variables

private var gamobjTexture : Object[] = Resources.LoadAll("picConWomCleCon", Texture2D);

// GUI
function OnGUI ()
{
	GUI.Button (Rect (0, 0,64,60), gamobjTexture[1]);
}

Alternately:

private var gamobjTexture : Texture2D[] = Resources.LoadAll("picConWomCleCon", Texture2D);

Gives this error:
InvalidCastException: Cannot cast from source type to destination type.

Am I missing something obvious?

This will save me a lot of time if I can get this going.

Thanks.

resources loaded are resources.

they are no game object, meshes or textures.
you first need to use Instantiate to actually create a corresponding usable “game media object” from the resource data you loaded

Thank you for your response.

I see the various forms of instantiation but am unsure of how to implement your suggestion.

Could you drop a line of code for me as example?

Thanks.

Its actually very simple :slight_smile:

You can just use (ClassOfObjectYouInstantiate)Object.Instantiate( yourResourceObject)

in your case the ( … ) would be (Texture2D) for example.

you can check out the script reference on instantiate for more information.