How would I cast "someString" in the following code in order to get it to work?

I have some textures in the Resources folder and imported it with the Texture Importer.

In the C# script, I manipulate a type String that is catenated with the texture’s names.

How would I cast “someString” in the following code in order to get it to work?

GUILayout.Button(Resources.Load(someString), GUILayout.Width(150))

Thanks CSDG

I don’t get your problem… You said “someString” is a string there is no need to cast the string. I guess you want to cast the object that is returned by Resources.Load into a Texture2D.

Another thing:
You would call Resources.Load several times each frame. You only should load the texture once, at start:

private Texture2D myGUITexture = null;
void Start()
{
    [...] // build the string
    myGUITexture = (Texture2D)Resources.Load(someString,typeof(Texture2D));
    if (myGUITexture == null)
    {
        Debug.LogWarning("Texture '"+someString+" no found");
    }
}

void OnGUI()
{
    [...]
    GUILayout.Button(myGUITexture, GUILayout.Width(150));
    [...]
}