void OnDrop(RaycastHit hit) { SetPhysics(null); GameObject obj = GetHolding().GetObject(); newColider = false; if (obj.GetComponent <Move_S>() != null) //board/plate/tray dropped { if (obj.CompareTag("Plate")) //checking if its a plate { if (Physics.Raycast(guide.position, -Vector3.up, out hit, 5f)) { float dist = Vector3.Distance(guide.position, hit.point); StartCoroutine(BreakStuff(dist, obj)); } } Move_S m = GetHolding().GetObject().GetComponent <Move_S>(); if (m.ListOfFood().Count > 0) //checking if theres food on the object { foreach (Food_O f in m.ListOfFood()) //resetting varibales for each food object { f.GetComponent <IPhysics>().GetMarker().SetOccupation(false); f.SetOnSurface(false); f.ChangeDrag(3); f.firstOnStack = null; f.SetMarker(null); StartCoroutine(CheckObjectCount.CheckPrefabCount(f.gameObject)); GameManager.dropCount++; } m.ListOfFood().Clear(); } m.MarkerList().Clear(); m.AddMarkerChildren(); } else if (obj.GetComponent <Food_O>() != null) //if food dropped { Food_O food = obj.GetComponent <Food_O>(); StartCoroutine(CheckObjectCount.CheckPrefabCount(food.gameObject)); if (food.foodStack.Count > 0) { foreach (Food_O f in food.foodStack) //resetting varibales { f.firstOnStack = null; StartCoroutine(CheckObjectCount.CheckPrefabCount(f.gameObject)); GameManager.dropCount++; f.GetMarker().SetOccupation(false); f.SetMarker(null); } food.foodStack.Clear(); } } SetInteract(null); }
IEnumerator BreakStuff(float distance, GameObject theObj) //for when a plate is dropped { theObj.GetComponent <Collider>().isTrigger = true; yield return(new WaitForSeconds(Mathf.Sqrt(distance / -(Physics.gravity.y / 2)))); theObj.GetComponent <Collider>().isTrigger = false; for (int i = 0; i < 5; i++) { GameObject d = Instantiate(debris, theObj.transform.position, Quaternion.identity); StartCoroutine(CheckObjectCount.CheckPrefabCount(d)); } GameManager.dropCount++; Destroy(theObj); }