Advertisement
Guest User

Untitled

a guest
Oct 1st, 2014
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. Vector2 world_position = Camera.main.ScreenToWorldPoint(Input.mousePosition) as Vector2;
  2.  
  3. public class InventoryItem : Monobehaviour
  4. {
  5. public Transform item_prefab;
  6. private void Start()
  7. {
  8. if ( item_prefab == null )
  9. {
  10. Debug.LogError("Item prefab is not valid.");
  11. }
  12. }
  13. }
  14.  
  15. public void OnItemDrop(GameObject item)
  16. {
  17. // Get world position
  18. Vector2 item_world_position = Camera.main.ScreenToWorldPoint(Input.mousePosition) as Vector2;
  19. // Get the prefab to instantiate
  20. Transform item_prefab = item.GetComponent<InventoryItem>().item_prefab;
  21.  
  22. // Instantiate it to world position
  23. Instantiate(item_prefab, item_world_position, new Quaternion());
  24.  
  25. // You can do this if you want your item sprite to disappear
  26. // Destroy(item);
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement