Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using UnityEngine.UI;
- using UnityEngine.EventSystems;
- public class CraftingClickAndDrag : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler {
- public static Vector3 startPosition;
- public static GameObject itemBeingDragged;
- Transform startParent;
- public int slotNumber;
- public static int currentSlotNumber;
- Camera camera;
- void Start()
- {
- camera = GameObject.Find("Main Camera").GetComponent<Camera>();
- }
- #region IBeginDragHandler implementation
- public void OnBeginDrag(PointerEventData eventData)
- {
- itemBeingDragged = gameObject;//(GameObject)Instantiate(gameObject, transform.position, transform.rotation);
- startPosition = transform.position;
- startParent = transform.parent;
- GetComponent<CanvasGroup>().blocksRaycasts = false;
- currentSlotNumber = slotNumber;
- GameObject.Find("craftingCanvas").GetComponent<ExplorationCraftingUI>().dragItemViewOn(slotNumber);
- }
- #endregion
- #region IDragHandler implementation
- public void OnDrag(PointerEventData eventData)
- {
- Vector3 position = camera.ScreenToWorldPoint(Input.mousePosition);
- transform.position = new Vector3 (position.x, position.y, 0);
- }
- #endregion
- #region IEndDragHandler implementation
- public void OnEndDrag(PointerEventData eventData)
- {
- Debug.Log("END DRAG");
- itemBeingDragged = null;
- transform.position = startPosition;
- GetComponent<CanvasGroup>().blocksRaycasts = true;
- }
- #endregion
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement