- Home /
Check if items are in correct slot using Unity3D UI
I am developing a game in which there are several slots on screen and after performing real life calculations the player chooses the items from its inventory and add it to certain slot present. Now when the player clicks the play button it checks if the item that player put in the slot are in correct slots or not.
I am unable to figure out how should I check if a particular panel has a particular game-object as its child. I am currently using a common slot script to all panels.
public class Slot : MonoBehaviour, IDropHandler{
public GameObject item {
get {
if (transform.childCount>0) {
return transform.GetChild (0).gameObject;
}
return null;
}
}
public void OnDrop (PointerEventData eventData)
{
if (!item) {
DragHandeler.itemBeingDragged.transform.SetParent (transform);
ExecuteEvents.ExecuteHierarchy<IHasChanged> (gameObject, null, (x, yield) => x.HasChanged ());
}
}
Do I need to create separate slot script for each panel, if so how can I distinguish between each slot?
Comment