- Home /
Resources.Load problem
hey guys. i have an item generator script and a resources folder with item icons. I use these for my Inventory and Loot windows. However, I'm not getting Resources.Load in the Resources functions. Here's the item script:
using UnityEngine;
public static class ItemGenerator { public const int BASE_MELEE_RANGE = 1; public const int BASE_RANGED_RANGE = 5;
private const string WEAPON_PATH = "Icons/Weapons/Melee/"; private const string POTION_PATH = "Icons/Potions/Health/";
public static Item CreateItem() { Item item = CreateWeapon();
// private string _name; item.Value = Random.Range(1, 101); item.Rare = RarityTypes.Common; item.MaxDurability = Random.Range(50, 61); item.CurDurability = item.MaxDurability;
return item; }
private static Weapon CreateWeapon() { Weapon weapon = CreateMeleeWeapon();
return weapon; }
private static Weapon CreateMeleeWeapon() { Weapon meleeWeapon = new Weapon();
string[] itemNames = new string[3]; itemNames[0] = "Blue Sword"; itemNames[1] = "Health Soda"; itemNames[2] = "Max Health Soda";
meleeWeapon.Name = itemNames [Random.Range(0, itemNames.Length)];
meleeWeapon.MaxDamage = Random.Range(5, 11); meleeWeapon.DamageVariance = Random.Range(.2f, .76f); meleeWeapon.TypeOfDamage = DamageType.Slash; meleeWeapon.MaxRange = BASE_MELEE_RANGE;
// meleeWeapon.Icon = Resources.load(WEAPON_PATH + POTION_PATH + meleeWeapon.Name) as Texture2D;
return meleeWeapon; }
}
public enum ItemType { Armor, Weapon, Potion, Clothing }
Do you have any suggestions? Thanks
Answer by whydoidoit · Jul 20, 2012 at 02:41 PM
I imagine that you have created a class or script with the name Resources which is hiding the real Unity one. Rename that and it should work.
The correct capitalization is Resources.Load by the way.
I just looked through all my current scripts. None of them had Resources. However, someone on this website said getting this function involves accessing the hardrive. Do you think that's true?
Well using it reads data from the compiled resources. Not sure what you mean? What isn't happening? It won't compile or it doesn't load your resources?
It's not compiling. I type in "Load" in $$anonymous$$onoDevelop and it's not there in the functions list for Resources
This tutorial I'm following might help: