public override void activate(character player) { if (player.seedCount > 0 && state == plantState.unplanted) { player.useSeed(); int random = Random.Range(0, produce.Length); produce[random].transform.GetChild(0).gameObject.SetActive(true); produceIndex = random; produceStage = 0; state = plantState.growing; growthRoutine = StartCoroutine(growPlant()); } if (state == plantState.ready) { Debug.Log("Collected Plant"); state = plantState.unplanted; produce[produceIndex].transform.GetChild(produceStage).gameObject.SetActive(false); plantReady.Stop(); } base.activate(player); }
IEnumerator growPlant() { float timer = 0f; while (timer < growthInterval) { timer += Time.deltaTime; yield return(new WaitForEndOfFrame()); } if (produceStage == produce[produceIndex].transform.childCount - 1) { state = plantState.ready; plantReady.Play(); } else { produce[produceIndex].transform.GetChild(produceStage).gameObject.SetActive(false); produceStage++; produce[produceIndex].transform.GetChild(produceStage).gameObject.SetActive(true); growthRoutine = StartCoroutine(growPlant()); } }
public void CircleOfLife() { if (isDying) { if (lushPlant && lushPlant.activeSelf) lushPlant.SetActive (false); deathTimer += Time.deltaTime; if (currentPlantState == plantState.sprouting) { timer = requiredTime; if (wiltedSapling && !wiltedSapling.activeSelf) wiltedSapling.SetActive (true); } else { timer = 0; if (currentPlantState == plantState.flower) { anim.SetTrigger ("testTrigger"); currentPlantState = plantState.adult; requiredTime = requiredTimeToFlower; } if (wiltedPlant && !wiltedPlant.activeSelf) wiltedPlant.SetActive (true); if (deathTimer >= requiredTimeToDie) { List <GameObject> hexesTemp = HF.HexesList (waterReleaseRadius, xPos, yPos); for (int i = 0; i < hexesTemp.Count; i ++) { hexesTemp [i].GetComponent<Resourse> ().water += waterRelease; } hexesTemp = HF.HexesList (nutrientReleaseRadius, xPos, yPos); for (int i = 0; i < hexesTemp.Count; i ++) { hexesTemp [i].GetComponent<Resourse> ().nutrients += nutrientRelease; } } } } else { if (lushPlant && !lushPlant.activeSelf) lushPlant.SetActive (true); if (wiltedPlant && wiltedPlant.activeSelf) wiltedPlant.SetActive (false); if (wiltedSapling && wiltedSapling.activeSelf) wiltedSapling.SetActive (false); deathTimer = 0; if (timer >= requiredTime) { timer -= requiredTime; if (currentPlantState == plantState.sprouting) resourceDeltaTime = timer; anim.SetTrigger ("testTrigger"); if(currentPlantState == plantState.adult) { currentPlantState = plantState.flower; requiredTime = requiredTimeToSeed; } else { if (currentPlantState != plantState.sprouting) { GameInterFace.seeds[seedIndex] += Random.Range(seedMin, seedMax + 1); SeedFling(); if(particle) particle.Play(); } currentPlantState = plantState.adult; requiredTime = requiredTimeToFlower; } } if (currentPlantState != plantState.sprouting) { List <GameObject> hexesTemp = HF.HexesList (waterProduktionRadius, xPos, yPos); for (int i = 0; i < hexesTemp.Count; i ++) { hexesTemp [i].GetComponent<Resourse> ().water += resourceDeltaTime * waterProduktion; } hexesTemp = HF.HexesList (nutrientProduktionRadius, xPos, yPos); for (int i = 0; i < hexesTemp.Count; i ++) { hexesTemp [i].GetComponent<Resourse> ().nutrients += resourceDeltaTime * nutrientProduktion; } } } }