Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Vector2 world_position = Camera.main.ScreenToWorldPoint(Input.mousePosition) as Vector2;
- public class InventoryItem : Monobehaviour
- {
- public Transform item_prefab;
- private void Start()
- {
- if ( item_prefab == null )
- {
- Debug.LogError("Item prefab is not valid.");
- }
- }
- }
- 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
- // Destroy(item);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement