Hi, I’m not sure if this is possible, but basically I wanna do:
void SpawnItem(Item item){
GameObject newItem = Instantiate (itemIcon, transform.position, Quaternion.identity) as GameObject;
newItem.GetComponent<Item> () = item;
}
And lets just say I call that function after I figure out which item from my inventory to spawn.
I have a List(Item), and Item is derived from Mono. I want to know if it’s possible to:
- Spawn a Gameobject with the component directly referring to the same instance from my List
- When I pick up the Gameobject, I “take” the component, put it in my list, destroy the Gameobject
This is actually related to Unity UI drag/drop icon. When I drag and drop an icon, I want each icon to also bring the correct reference of the instance. Whenever I do that, the newly created icon in my inventory(that has a ), always have the default instance.
I tried putting a
ItemObject itemS = newItem.GetComponent<Item> ();
itemS = item;
But of course that just refers itemS to the (Item) component in the newly instantiated object, then refers it to item, thus not really changing what newItem.GetComponent refers to at all.