1
votes

I have strings for the path to the Texture2D element I want to load from the List string that is filled dynamically from an XML file into the List Texture.

public List commands; public List icons = new List(); void Awake() { int i = 0; foreach (string element in commands) { icons.Insert(i, icons[i].Resources.Load(element, Texture2D)); //error line i++; }

}

Here is what I have so far but I'm generating the following compiler errors in Unity:

error CS1061: Type UnityEngine.Texture' does not contain a definition for Resources' and no extension method Resources of type `UnityEngine.Texture could be found (are you missing a using directive or an assembly reference?)

error CS1502: The best overloaded method match for `System.Collections.Generic.List.Insert(int, UnityEngine.Texture)' has some invalid arguments

error CS1503: Argument #2' cannot convert object' expression to type `UnityEngine.Texture'

It seems I cannot use Resources.Load directly with the icons elements as I am attempting to do but I'm at a loss for how else to go about it.

1
Check out UnityAnswers, too :) ( answers.unity3d.com )Mark Simpson

1 Answers

1
votes
foreach (string element in commands)
        {
         tex = (Texture2D) Resources.Load(element);
         icons.Add(tex);
        }

So I figured it out; above modifications are the changes.