As your question, now clearer seems to be more about design and not so much a technical question I change my answer a bit.
Your first attempt was the right one. Your sprite contains a drag&drop component. But it's necessary that it also contains the prefab it will instantiate once dropped in the game world. The main design is, from an inventory item perspective:
- I know what prefab I represent
- When player drop me on the scene I get the Mouse position and Instantiate the prefab I represent
You can add a 3rd step if you want the item sprite to its initial position in the inventory (but the inventory item will have to save its initial position before drag&drop begins).
Let me rephrase your question as I understand it.
So you have an inventory (somewhere on the screen) full of draggable sprites/objects and you want to instantiate a prefab when the player drop it somewhere on the screen. As you seem to have drag/drop behaviour working, the real problem is about instantiating/activating things at the right place on screen.
If that's correct, I'd say the first technique you tried was a good one. (note that the second one, using prefabs, would totally work but it's not as "clean and easy" in my humble opinion).
Let say that the inventory is composed of sprites. When you drop something from your inventory you actually need two important informations: the drop position and the object to instantite.
The position is actually given by the mouse position. As it's a 2D game you're working on you just have to convert the mouse position, given in screen space, in a world space position. It's pretty easy using the Camera.ScreenToWorldPoint method.
Something like :
Vector2 world_position = Camera.main.ScreenToWorldPoint(Input.mousePosition) as Vector2;
// using Vector2 instead of Vector3 is not mandatory even in a 2D game, but I prefer.
So the trick here is to somehow add a property to the sprites of inventory. Simply add a component (on every inventory object), let's call it
InventoryItem, which has the prefab you need to instantiate in a
public Transform field.
Something like :
public class InventoryItem : Monobehaviour
public Transform item_prefab;
private void Start()
if ( item_prefab == null )
Debug.LogError("Item prefab is not valid.");
Now, when player drop an inventory item, it's easy to know what prefab to Instantiate and where to instantiate it.
public void OnItemDrop(GameObject item)
// Get world position
Vector2 item_world_position = Camera.main.ScreenToWorldPoint(Input.mousePosition) as Vector2;
// Get the prefab to instantiate
Transform item_prefab = item.GetComponent<InventoryItem>().item_prefab;
// Instantiate it to world position
Instantiate(item_prefab, item_world_position, new Quaternion());
// You can do this if you want your item sprite to disappear
Note that this code is untested... but it might work :)
I hope it helps.