// Update is called once per frame void Update() { // if(currentMug!=null) // Debug.Log(gameObject.name+" stock: "+stock.Count+ " - CurrentMug: "+currentMug.name+" (Dirty: "+currentMug.GetComponent<Mug>().dirty+")"); //Set current mug if there's stock if (currentMug is null && stock.Count > 0) { currentMug = stock[0]; stock.RemoveAt(0); Mug mug = currentMug.GetComponent <Mug>(); if (mug.content != null)//Empty mug { mug.consume(); prepTimer = 0.0f; } else if (!mug.dirty)//Mug already clean { prepTimer = prepTime; } if (UIPrepTimer != null) //Display UI prep timer { UIPrepTimer.SetValue(prepTimer / prepTime); // UIPrepTimer.DisplayIcon(false); UIPrepTimer.gameObject.SetActive(true); } } }
} //Stock of product //Handle objects interactions w/ Workshop //Return wether the object is taken from tavernkeeper public override bool use(GameObject userObject) { if (userObject != null) { // Debug.Log(userObject.tag); //TODO : Gérer Grabable qui ne sont pas des mugs ? if (userObject.tag == "Grabable" && currentMug is null) //Try to stock Mug into workshop { Mug mug = userObject.GetComponent <Mug>(); if (mug != null && mug.content is null && !mug.dirty && Stock > 0) //Mug clean & empty + remaining stock in workshop { Debug.Log(userObject.name + " stocked in " + gameObject.name); mug.take(); currentMug = userObject; if (UIPrepTimer != null) //Display UI prep timer { prepTimer = 0.0f; UIPrepTimer.SetValue(prepTimer / prepTime); UIPrepTimer.DisplayIcon(product_sprite); UIPrepTimer.gameObject.SetActive(true); } return(true); //Object taken } else { Debug.Log(userObject.name + " cannot be filled with " + product_name + " -stock:" + Stock); } } else if (userObject.tag == "Player" && prepTimer < prepTime && currentMug != null) //Prepare currentMug { continueUse(userObject); } else if (userObject.tag == "Player" && prepTimer >= prepTime) //Give tavernkeeper currentMug if finished preparation { Tavernkeeper_controller player = userObject.GetComponent <Tavernkeeper_controller>(); Mug mug = currentMug.GetComponent <Mug>(); if (player != null && mug != null) { Debug.Log(gameObject.name + " give " + currentMug.name + " filled with " + product_name + " to " + userObject.name); //Fill mug mug.fill(new Consumable(product_name, product_value, product_sprite)); Stock--; UIPrepTimer.gameObject.SetActive(false); //Turn off UI prep timer //Give mug player.grab(currentMug); currentMug = null; } } }