public void SatisfyNeed(horseNeed need, float value) { switch (need) { case horseNeed.FOOD: Food += value; break; case horseNeed.WATER: Water += value; break; case horseNeed.HAPPINESS: Happiness += value; if (heartParticles == null) { heartParticles = Instantiate(PrefabManager.instance.happinessParticles, headBone.position, Quaternion.identity).GetComponent <ParticleSystem> (); } else { heartParticles.transform.position = headBone.position; } heartParticles.GetComponent <DeactivateAfterTime> ().Activate(); heartParticles.Play(); break; case horseNeed.HYGIENE: Hygiene += value; if (dustParticles == null) { dustParticles = Instantiate(PrefabManager.instance.dustParticles, withersBone.position, Quaternion.identity).GetComponent <ParticleSystem> (); } else { dustParticles.transform.position = withersBone.position; } dustParticles.GetComponent <DeactivateAfterTime> ().Activate(); dustParticles.Play(); break; case horseNeed.ENERGY: Energy += value; break; } }
public void UpdateNeedsDisplay(horseNeed need, float newValue, bool updateRidingUI = false) { Image imageToUpdate = foodImage; switch (need) { case horseNeed.FOOD: imageToUpdate = foodImage; break; case horseNeed.WATER: imageToUpdate = waterImage; break; case horseNeed.HAPPINESS: imageToUpdate = happinessImage; break; case horseNeed.ENERGY: if (updateRidingUI) { imageToUpdate = UI.instance.ridingUI.energyBar; } else { imageToUpdate = energyImage; } break; } imageToUpdate.fillAmount = newValue / 100; if (newValue >= 40) { imageToUpdate.color = Color.green; } else if (newValue >= 20) { imageToUpdate.color = Color.yellow; } else { imageToUpdate.color = Color.red; } }
private Consumable FindConsumableInRange(horseNeed need) { Consumable result = null; Consumable[] allConsumables = FindObjectsOfType <Consumable> (); float maxDist = 60f; float minDist = maxDist; RaycastHit hit; for (int i = 0; i < allConsumables.Length; ++i) { if (allConsumables [i].needSatisfiedByThis == need) { float dist = Vector3.Distance(horse.horseStats.headBone.position, allConsumables [i].transform.position); bool isVisible = false; Debug.DrawRay(horse.horseStats.headBone.position, allConsumables [i].transform.position - horse.horseStats.headBone.position, Color.red, 2f); if (Physics.Raycast(horse.horseStats.headBone.position, allConsumables [i].transform.position - horse.horseStats.headBone.position, out hit, maxDist)) { //Debug.Log ("horse looking for consumable, raycast hit " + hit.collider.name + " with tag: " + hit.collider.tag); if (hit.collider.tag.Equals("Consumable")) { isVisible = true; } } //Debug.Log ("horse looking at " + allConsumables [i].name + " dist: " + dist + ", isvisible: " + isVisible + " has remaining value: " + allConsumables[i].remainingNeedValue); if (dist < minDist && isVisible && allConsumables[i].remainingNeedValue > 0 && allConsumables[i].enabled) { minDist = dist; result = allConsumables [i]; } } } return(result); }
public float GetNeedValue(horseNeed need) { switch (need) { case horseNeed.FOOD: return(Food); case horseNeed.WATER: return(Water); case horseNeed.HAPPINESS: return(Happiness); case horseNeed.HYGIENE: return(Hygiene); case horseNeed.ENERGY: return(Energy); default: Debug.LogWarning("get invalid need"); return(Food); } }