IEnumerator CookAfter(float time, GameObject Obj, Consumable consu, int index) { FirePlace _fp = this.GetComponentInChildren <FirePlace>(); float iterator = time; //Debug.Log(iterator); bool isRoutine = false; bool stop = false; while (iterator > 0) { Debug.Log("DOWHILE: " + iterator.ToString()); if (isRoutine == false) { if (_fp.isLit == false) { Obj.layer = 8; // COULD MAKE SO IT CARRIES ON IF LIT INSTEAD OF THROWING IT OFF. _CookingSlots[index].used = false; _CookingSlots[index].obj = null; for (int i = 0; i < Obj.GetComponent <ID>().Colliders.Length; i++) { Obj.GetComponent <ID>().Colliders[i].enabled = true; } Obj.GetComponent <Rigidbody>().isKinematic = false; Obj.GetComponent <Rigidbody>().useGravity = true; stop = true; yield return(null); StopCoroutine("CookAfter"); break; } isRoutine = true; yield return(new WaitForSeconds(1)); iterator--; consu.timeToCook--; // remove line if want to start from start isRoutine = false; } } // every second -= 1 // check if fireplace still lit if (stop == false) { Debug.Log("enterpass"); consu.enabled = true; consu.Cook(); Obj.layer = 8; _CookingSlots[index].used = false; _CookingSlots[index].obj = null; for (int i = 0; i < Obj.GetComponent <ID>().Colliders.Length; i++) { Obj.GetComponent <ID>().Colliders[i].enabled = true; } } }