public class InventoryController : MonoBehaviour
{
public Transform selectedItem, selectedSlot, originalSlot;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButton(0))
{
selectedItem.position = Input.mousePosition;
}
else if (Input.GetMouseButtonUp(0))
{
selectedItem.localPosition = Vector3.zero;
}
}
}
And the script attached to the slot
public class SlotController : MonoBehaviour
{
void OnMouseOver()
{
transform.parent.GetComponent<InventoryController>().selectedSlot = this.transform;
}
}
There is box collider on the slot image I also tried to use OnMouseEnter but when I move the mouse on the slot it dosen’t assign it to the inventory controller.
Transform.localPosition is the position relative to its parent transform, so i dont think you need to set that to 0. I dont have a lot of mobile experience, but touches are very similar to mouse clicks. That means you can basically use any standard approach to inventory management, as long as it does not use mouse over.
Inventories are a pretty common thing. You can either do them purely script based, or using gameobjects. Did you try watching some tutorials? Brackeys and others made some tutorials on them, like this one:
You way wanna watch the previous episode as well, for how to create the visuals and relations of the inventory.