Question by
maawali · Jan 19, 2017 at 05:43 AM ·
drag-and-drop
hey guys, I'm doing drag n drop to snap in place but i need to count the sprite that did snap, help me guys im new to gaming.
using UnityEngine; using System.Collections; using UnityEngine.EventSystems; using UnityEngine.UI;
public class Slot : MonoBehaviour, IDropHandler { public int saveVar = 0; public GameObject SlotTag; public Text displayText;
private int countError = 0;
public void Start()
{
displayText.text = " ";
}
public GameObject item{
get{
if (transform.childCount > 0) {
return transform.GetChild (0).gameObject;
}
return null;
}
}
#region IDropHandler implementation
public void OnDrop (PointerEventData eventData)
{
if (!item)
{
CheckCon();
}
}
public void CheckCon()
{
if (SlotTag.tag == DragHandler.itemBeingDragged.tag) {
DragHandler.itemBeingDragged.transform.SetParent(transform);
int count = 0;
count = count + 1;
Debug.Log(count);
}
else
{
if( countError >= 3)
{
displayText.text = "Wrong ";
}
else
{
countError += 1;
Debug.Log(countError);
}
}
}
#endregion
}
Comment