Added overlay to view nutrient mapping
This commit is contained in:
@@ -7,6 +7,7 @@ public class Plant : MonoBehaviour
|
||||
private float healthCurrent;
|
||||
private float nutrientNeed;
|
||||
private float growthRate;
|
||||
private float nutrientsConsumed;
|
||||
public bool isAlive;
|
||||
|
||||
private GameObject visualPrefab;
|
||||
@@ -29,6 +30,7 @@ public class Plant : MonoBehaviour
|
||||
{
|
||||
visual = Instantiate(visualPrefab, transform);
|
||||
healthCurrent = healthMax;
|
||||
nutrientsConsumed = 0;
|
||||
isAlive = true;
|
||||
}
|
||||
|
||||
@@ -37,22 +39,26 @@ public class Plant : MonoBehaviour
|
||||
{
|
||||
Terrain terrain = Core.instance.ground;
|
||||
NutrientController nutrientCont = Core.instance.nutrientCont;
|
||||
float x = transform.position.x / terrain.terrainData.size.x;
|
||||
float y = transform.position.y / terrain.terrainData.size.y;
|
||||
float nutrientsAvailable = nutrientCont.GetNutrients(x, y);
|
||||
|
||||
if(nutrientNeed > nutrientsAvailable)
|
||||
float x = transform.position.x / terrain.terrainData.size.x;
|
||||
float y = transform.position.z / terrain.terrainData.size.z;
|
||||
|
||||
float nutrientsAvailable = nutrientCont.GetNutrients(x, y);
|
||||
float nutrientsNeededFrame = (nutrientNeed * Time.deltaTime);
|
||||
if (nutrientsNeededFrame > nutrientsAvailable)
|
||||
{
|
||||
healthCurrent -= Time.deltaTime * (0.1f * healthMax);
|
||||
healthCurrent -= Time.deltaTime * 0.1f * healthMax;
|
||||
}
|
||||
else
|
||||
{
|
||||
visual.transform.localScale += visual.transform.localScale * (growthRate * Time.deltaTime);
|
||||
nutrientCont.UseNutrients(x, y, (nutrientNeed * Time.deltaTime));
|
||||
nutrientCont.UseNutrients(x, y, nutrientsNeededFrame);
|
||||
nutrientsConsumed += nutrientsNeededFrame;
|
||||
}
|
||||
|
||||
if (healthCurrent <= 0)
|
||||
{
|
||||
nutrientCont.AddNutrients(x, y, (nutrientsConsumed * 0.9f));
|
||||
isAlive = false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user