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

1 Answer

1

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