I’m trying to recreate a weight based inventory. The inventory doesn’t care about slots or item counts, its entirely based on the weight of items. Ultima Online had a system like this and by dragging items within a bag it would change their Z order to render on top.
So my question is, how do I drag a game object into a canvas window. I assume when the mouse releases it will destroy the game object and create a image representation of that object and vice versa when I drag it out of the container to game space it will create a prefab.
Heres an example of the feature I’m trying to recreate:
Heres the basic code I have right now that just allows me to drag a game object around game space:
void OnMouseDown()
{
mZCoord = Camera.main.WorldToScreenPoint(
gameObject.transform.position).z;
// Store offset = gameobject world pos - mouse world pos
mOffset = gameObject.transform.position - GetMouseAsWorldPoint();
}
private Vector3 GetMouseAsWorldPoint()
{
// Pixel coordinates of mouse (x,y)
Vector3 mousePoint = Input.mousePosition;
// z coordinate of game object on screen
mousePoint.z = mZCoord;
// Convert it to world points
return Camera.main.ScreenToWorldPoint(mousePoint);
}
void OnMouseDrag()
{
transform.position = GetMouseAsWorldPoint() + mOffset;
}
}
What else do I need to get this off the ground?