x


Resources.Load texture problem

i want to make a pu system for my game and i want to desplay the icons of the power up and i've dont this

public class PowerUpContainer : MonoBehaviour {
    public List<EBasePowerUp> PuList;
    public Dictionary<string,Texture> icons=new Dictionary<string, Texture>();

    // Use this for initialization
    void Start () {
       DirectoryInfo dir=    new System.IO.DirectoryInfo("Assets/Textures/pu/");
       FileInfo[] files= dir.GetFiles();
       foreach(FileInfo f in files){
         icons.Add(f.Name.Substring(0,f.Name.Length-4),(Texture)Resources.Load(f.FullName,typeof(Texture)));
         Debug.Log("Loaded texture : "+f.Name);
       }
    }

    // Update is called once per frame
    void OnGUI () {
       Texture icon;
       Rect r=new Rect(10,100,30,20);
       foreach(EBasePowerUp p in PuList){

         if(icons.ContainsKey(p.GetType().Name)){
          icon=icons[p.GetType().Name];
          //........
          r.x+=r.width;
          if(r.x>90){
              r.x=10;
              r.y+=20;
          }
         }
       }

    }
}

but i have a problem, the texuter loades with no error, my dicionary contains the key so the if(icons.ContainsKey(p.GetType().Name)) is true... but the key value is null and i can't find the problem, the texture is loade without any error and is null... i have tryed to display all the textures that are in the dictionary and all are null... i think the problem is with "Resources.Load" but i'm a beginer in unity and i don't know so much

more ▼

asked Mar 26 '12 at 03:01 PM

HardStyle gravatar image

HardStyle
0 1 1 1

yes the files are loaded i have this debug log and its loading everything:

icons.Add(f.Name.Substring(0,f.Name.Length-4),(Texture)Resources.Load(f.FullName,typeof(Texture))); Debug.Log("Loaded texture : "+f.Name);

Mar 27 '12 at 05:49 AM HardStyle
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Does the files Array get populated? Put your textures into "Assets/Resources/..." folder, Resources.Load always looks for them there.

more ▼

answered Mar 27 '12 at 05:20 AM

Esa gravatar image

Esa
273 1 2 6

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2203
x666
x197
x14

asked: Mar 26 '12 at 03:01 PM

Seen: 808 times

Last Updated: Mar 27 '12 at 05:49 AM