Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

592
Views
Loading Texture list with Texture2D dynamically from file at RunTime in Unity

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.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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

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

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!