- Home /
Question by
riskaanisah · Nov 05, 2018 at 01:45 AM ·
drag-and-dropgame objecttrue
how make a branch from drag and drop like this?
what should I fix or add from the following code, so that I can check true or false when it's done dragging both ?`using UnityEngine; using System.Collections; using UnityEngine.EventSystems; using UnityEngine.SceneManagement;
public class Slot : MonoBehaviour, IDropHandler {
public float delay = 15;
public GameObject CorrectAnswerPopUp;
public GameObject CorrectAnswer;
public GameObject CorrectAnswer2;
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)
{
DragHandeler.itemBeingDragged.transform.SetParent(transform);
//ExecuteEvents.ExecuteHierarchy<IHasChanged>(gameObject, null, (x, y) => x.HasChanged());
}
if (DragHandeler.itemBeingDragged != null)
{
if (DragHandeler.itemBeingDragged == CorrectAnswer)
{
Debug.Log("benar");
StartCoroutine(LoadLevelAfterDelay(delay));
}
else
{
Debug.Log("salah");
}
}
}
#endregion
IEnumerator LoadLevelAfterDelay(float delay)
{
CorrectAnswerPopUp.SetActive(true);
yield return new WaitForSeconds(delay);
SceneManager.LoadScene("DragDrop2");
}
}`
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612181535im_/https://answers.unity.com/themes/thub/images/avi.jpg)