- Home /
Question by
NutellaDaddy · Mar 31, 2014 at 03:14 AM ·
c#resourcesresources.load
Why does resources.load not work or what am I doing wrong?
I am trying to make a path file that directs the system to my folder with all of my icons in it so i can use them ,but for some reason it is not working. When I start the game the icons just don't show up in the crate or inventory. Am I using it wrong or something? Here is the script that I am using.
using UnityEngine;
using System.Collections;
public class ItemGenerator : MonoBehaviour
{
//PATH NAME RIGHT HERE
private const string meleeWeaponPath = "Icons/Weapons/Melee";
void Start()
{
}
public static Item CreateItem()
{
//DECIDE WHAT TYPE OF ITEM TO MAKE
//CALL THE METHOD TO CREATE THAT BASE ITEM TYPE
Item item = CreateWeapon ();
//FILL IN ALL THE VALUES FOR THAT ITEM TYPE
item.name = "W: " + Random.Range (0, 100);
//RETURN NEW ITEM
return item;
}
private static Weapon CreateWeapon()
{
Weapon weapon = CreateMeleeWeapon();
return weapon;
}
private static Weapon CreateMeleeWeapon()
{
Weapon meleeWeapon = new Weapon (10.0f, 0.0f, 3, false, 0, false);
//IN THE ARRAY BELOW YOU DEFINE ALL THE NAMES OF THE ITEMS
string[] weaponNames = new string[3];
weaponNames[0] = "Machete";
weaponNames[1] = "Hunting Knife";
weaponNames[2] = "Handmade Hachet";
meleeWeapon.name = weaponNames[Random.Range(0,weaponNames.Length)];
meleeWeapon.description = "A fast bladed weapon";
//I AM TRYING TO USE RESOURCES.LOAD RIGHT HERE
meleeWeapon.icon = Resources.Load (meleeWeaponPath + meleeWeapon.name) as Texture2D;
meleeWeapon.rarity = RarityType.Common;
meleeWeapon.curDurability = 150.0f;
meleeWeapon.maxDurability = 150.0f;
meleeWeapon.weightAmount = 1;
return meleeWeapon;
}
}
public enum ItemType
{
Armor,
Weapon,
Consumable,
Placeable
}
Please help me!
Comment
Best Answer
Answer by brycedaawg · Mar 31, 2014 at 03:44 AM
At line 7 you have:
private const string meleeWeaponPath = "Icons/Weapons/Melee";
which should be:
private const string meleeWeaponPath = "Icons/Weapons/Melee/";
note the extra '/' near the end of the line.