//Display cloud watering for 4 seconds public IEnumerator makeCloud() { string currentPlant = Models[i].name; //Make sure the plant is ready to be rewatered int waterInterval = shedManager.GetPlantFeature(currentPlant, "waterInterval"); int lastWatered = shedManager.GetPlantFeature(currentPlant, "lastWatered"); DateTime now = DateTime.Now; int currentTime = (int)now.Subtract(DateTime.MinValue).TotalMinutes; int lastWateredDisplay = currentTime - lastWatered; if (waterInterval <= lastWateredDisplay) { //add experience int experienceGained = shedManager.GetPlantFeature(currentPlant, "experiencePerWater"); int currentExperience = shedManager.GetPlantFeature(currentPlant, "experience") + experienceGained; shedManager.SetPlantFeature(currentPlant, "experience", currentExperience); shedManager.Save(); int experienceToGrow = shedManager.GetPlantFeature(currentPlant, "experienceToGrow"); int experienceToComplete = shedManager.GetPlantFeature(currentPlant, "experienceToComplete"); Models[i].SetActive(false); Models[i + 1].SetActive(false); Models[i + 2].SetActive(false); if (currentExperience < experienceToGrow) { //play small version animation Models[i + 1].SetActive(true); } else if (currentExperience >= experienceToGrow && currentExperience < experienceToComplete) { //play medium animation Models[i + 2].SetActive(true); } else { //play full grown plant animation Models[i].SetActive(true); } //Water plant shedManager.SetPlantFeature(currentPlant, "lastWatered", currentTime); shedManager.Save(); RainCloud.SetActive(true); yield return(new WaitForSeconds(4)); RainCloud.SetActive(false); } else { Debug.Log("It's too early to water this plant again!"); } }
public void buyPlant() { //get the name of the button currently pressed (should match it's inner text so this is fine). string selectedPlantString = EventSystem.current.currentSelectedGameObject.name; string selectedPlant = selectedPlantString.Substring(4); //Cut off the word "buy " //Get the current plants stats Dictionary <string, int> currentPlantStats = storePlants[selectedPlant]; int waterInterval = currentPlantStats["waterInterval"]; int experience = currentPlantStats["experience"]; int experiencePerWater = currentPlantStats["experiencePerWater"]; int experienceToGrow = currentPlantStats["experienceToGrow"]; int experienceToComplete = currentPlantStats["experienceToComplete"]; //Make sure the plant doesn't already exist in the shed if (shedManager.shedPlants.ContainsKey(selectedPlant)) { return; } else { //Upon purchase, add this plants features to the shed. shedManager.SetPlantFeature(selectedPlant, "waterInterval", waterInterval); shedManager.SetPlantFeature(selectedPlant, "experience", experience); DateTime now = DateTime.Now; shedManager.SetPlantFeature(selectedPlant, "lastWatered", (int)now.Subtract(DateTime.MinValue).TotalMinutes); shedManager.SetPlantFeature(selectedPlant, "experiencePerWater", experiencePerWater); shedManager.SetPlantFeature(selectedPlant, "experienceToGrow", experienceToGrow); shedManager.SetPlantFeature(selectedPlant, "experienceToComplete", experienceToComplete); shedManager.Save(); } }