- Home /
Question by
VKronners · Mar 17, 2016 at 10:06 PM ·
gameobjectinstantiaterandom
Cards To Hand
Im creating a game for college and need to follow some rules so I have made this until now...
I need to generate cards from a complete Deck and each card i took need to be out of the deck... And i want the card to go directly to my hand.
using UnityEngine; using System.Collections; using UnityEngine.EventSystems;
public class draggable : MonoBehaviour, IBeginDragHandler,IDragHandler, IEndDragHandler {
public Transform parentToReturnTo = null;
public void OnBeginDrag(PointerEventData eventData){
//Debug.Log("On Begin Drag");
parentToReturnTo = this.transform.parent;
this.transform.SetParent (this.transform.parent.parent);
GetComponent<CanvasGroup> ().blocksRaycasts = false;
}
public void OnDrag(PointerEventData eventData){
// Debug.Log("On Drag");
this.transform.position = eventData.position;
}
public void OnEndDrag(PointerEventData eventData){
// Debug.Log("On End Drag");
this.transform.SetParent (parentToReturnTo);
GetComponent<CanvasGroup> ().blocksRaycasts = true;
}
}
The Code makes me an area that a can put cards in the table or at my hand I can still take table card and put on my hand but that's i'll fixed another time...
using UnityEngine; using System.Collections; using UnityEngine.EventSystems;
public class dropZone : MonoBehaviour, IDropHandler, IPointerEnterHandler, IPointerExitHandler {
public void OnPointerEnter(PointerEventData eventData){
//Debug.Log ("OnPointerEnter");
}
public void OnPointerExit(PointerEventData eventData){
//Debug.Log ("OnPointerExit ");
}
public void OnDrop (PointerEventData eventData){
Debug.Log (eventData.pointerDrag.name + " was dropped on " + gameObject.name);
draggable d = eventData.pointerDrag.GetComponent<draggable> ();
if (d != null){
d.parentToReturnTo = this.transform;
}
}
}
Comment