Another very important question. The scenario is this:
Player interacts with object to ‘collect’ it → Object is an instance of a Prefab → Object sends info about itself to player Inventory script → Object deletes itself as if ‘collected’ → Player instantiates said object later.
Edit(5/1/14): Getting the prefab via code is no longer a problem. (Originally I couldn’t figure out how to have the item send it’s own prefab to the inventory as a variable.) I’ve set up a custom Class that will hold each item’s info, and I can simply drag the item’s prefab to the correct spot on that item, then pass that variable of the new class to the inventory.
The issue I’ve run into now is trying to let the script set that class’s variable. Unity’s throwing me a lovely “Type ‘ItemInfo’ does not support slicing.” As I understand it, this has to do with #pragma strict, and while removing that will help, it can cause issues down the road. Here’s what I’m trying to do:
New Class:
public class ItemInfo{
var Name : String;
var Tag : String;
var PFB : GameObject;
var Amount : int;
var MaxStack : int;
var Weight : float;
var Durability : float;
var Level : int;
}
Item Script:
#pragma strict
public var info : ItemInfo;
function Start () : void
{
info[0] = "Test Sword";//Name
info[1] = this.gameObject.tag;//Tag
//info[2] is prefab, will assign through inspector
info[3] = 1;//Amount
info[4] = 1;//MaxStack
info[5] = 5.5;//Weight
info[6] = 100;//Durability
info[7] = 1;//Level
}
Should I be assigning these values some other way? Like info.Name = “Test Sword”; ?