void Update() { if (_rect != null) { if (isMouseOver()) { if (_currentSpawnedItem != null) { SpawnedSpecialItem spawnedItem = _currentSpawnedItem.GetComponent <SpawnedSpecialItem> (); if (Inventory.GetInstance().AddItem(spawnedItem.SpecialItem)) { addFromItemInfo(spawnedItem.SpecialItem, 100 * (Inventory.GetInstance().GetItems().Count - 1)); Destroy(_currentSpawnedItem); } else { spawnedItem.OnEndDrag(null); } } } } }
public void OnEndDrag(PointerEventData eventData) { Vector3 touch = Camera.main.ScreenToWorldPoint(Input.mousePosition); RaycastHit2D hit = Physics2D.Raycast(new Vector2(touch.x, touch.y), Vector2.zero, Mathf.Infinity); if (hit.collider != null) { Transform foundObject = hit.transform; SpawnedSpecialItem specialItem = foundObject.GetComponent <SpawnedSpecialItem> (); if (specialItem == null) { EndDragNormally(); } else { if (_messageBox == null) { _messageBox = GameObject.Find("MessageBox").GetComponent <UnityEngine.UI.Text> (); } if (specialItem.SpecialItem.InteractWith == SpecialItem.Name) { _messageBox.text = StringResources.GetLocalizedString(specialItem.SpecialItem.InteractMessage); Inventory.GetInstance().RemoveItem(SpecialItem.Name); Destroy(gameObject); Destroy(specialItem.gameObject); } else { _messageBox.text = StringResources.GetLocalizedString("incorrect_items_pair"); EndDragNormally(); } } } else { EndDragNormally(); } }