public void SetColor() { //get percentage of opposite color used based on health. Get that percentage of the dist from this and optimum color //and add that onto the optimum to get a blend of the 2 colors PlantRates pr = transform.root.gameObject.GetComponent <PlantRates>(); float colorPerc; if (pr.Health() >= healthToColorRatio) { colorPerc = NumOp.Cutoff(pr.Health() - GetComponent <Grow>().growthAmount, 0f, 1f); realTimeColor = NumOp.GetColorBlend(optimumColor, earlyColor, colorPerc); } else { float tmp = (healthToColorRatio - pr.Health()) * (1f / healthToColorRatio); colorPerc = NumOp.Cutoff(1f - (GetComponent <Grow>().growthAmount - tmp), 0f, 1f); realTimeColor = NumOp.GetColorBlend(optimumColor, lateColor, colorPerc); } realTimeColor = new Color(realTimeColor[0], realTimeColor[1], realTimeColor[2], alphaValue); if (debug) { print("percentage of opposite used: " + colorPerc.ToString()); } }
// Update is called once per frame void Update() { //make sure variables stay in acceptable range expectedGrowTime = NumOp.Cutoff(expectedGrowTime, 1, expectedGrowTime); growthTimeSkew = NumOp.Cutoff(growthTimeSkew, 0f, 1f); growthStages = NumOp.Cutoff(growthStages, 0, expectedGrowTime); PlantRates pr = transform.root.gameObject.GetComponent <PlantRates>(); //time till growth increases as efficiency lowers float actualGrowthEffic = (pr.currEfficiency - (pr.currEfficiency * growthTimeSkew)); currGrowTime = expectedGrowTime + (expectedGrowTime - (int)((float)expectedGrowTime * actualGrowthEffic)); int timeElapsed = transform.root.GetComponent <Timer>().timeElapsed; if (timeTillStart - timeElapsed <= 0) { hasStarted = true; } else { hasStarted = false; } if (hasStarted) { if (growthStages <= 0) { growthAmount = 1f; } else { int stageInterval = NumOp.Cutoff(currGrowTime, 0, currGrowTime) / growthStages; if (stageInterval <= 0) { growthAmount = 1f; } else { int stage = (timeElapsed - timeTillStart) / stageInterval; growthAmount = NumOp.Cutoff((float)stage / growthStages, 0f, 1f); } } } if (debug) { print(String.Format("Name: {0}, Full Growth Time: {1}hrs, TimeElapsed: {2}hrs", name, currGrowTime, (timeElapsed - timeTillStart))); } }