using UnityEngine; using UnityEngine.EventSystems; public class DropHandling : MonoBehaviour, IDropHandler, IPointerClickHandler { GameObject current; public Fact currentFact; public void OnDrop(PointerEventData eventData) { var scrollFact = gameObject.GetComponent<RenderedScrollFact>(); Debug.Log(eventData.pointerDrag.GetComponent<FactWrapper>().Fact.Label + " was dropped on " + gameObject.name + " " + scrollFact.ID + "/" + ScrollDetails.ParameterDisplays.Count + " label: " + scrollFact.Label); Destroy(current); current = Instantiate(eventData.pointerDrag, Vector3.zero, Quaternion.identity); //Set imageToChangeDefaultColor of current: Fix so that current won't take the color //the dragged item was having during animation current.GetComponent<ImageHintAnimation>().imageToChangeDefaultColor = eventData.pointerDrag.GetComponent<ImageHintAnimation>().imageToChangeDefaultColor; current.GetComponent<ImageHintAnimation>().ResetAnimation(); current.transform.SetParent(gameObject.transform, false); var rect = current.GetComponent<RectTransform>(); rect.anchorMin = new Vector2(0.5f, 0.5f); rect.anchorMax = new Vector2(0.5f, 0.5f); currentFact = eventData.pointerDrag.GetComponent<FactWrapper>().Fact; current.GetComponent<FactWrapper>().Fact = currentFact; Debug.Log("recieved Fact: " + currentFact.Id); CommunicationEvents.NewAssignmentEvent.Invoke(); } public void OnPointerClick(PointerEventData eventData) { Destroy(current); currentFact = null; CommunicationEvents.NewAssignmentEvent.Invoke(); } }