Whenever the enemy is hit by a water balloon and water gun, it decreases its health and is supposed to be displayed in the UI above their head. However, when I switch from the gun to the water balloons, the water balloon hits aren't being displayed by the UI anymore. I'm using a switch case for the UI health and I think the reason its not counting the water balloon hits is because the water balloon has a value of 20 while the water particles have a value of 2. So when I switch back to the balloons after using the water gun, the water balloon values don't match up with the case values, skipping it from working.
Is there a different way to do the health UI without the switch case? or is there a way to tell the switch case to know about the numbers in between?
WaterBalloonEnemy Script
Is there a different way to do the health UI without the switch case? or is there a way to tell the switch case to know about the numbers in between?
WaterBalloonEnemy Script
Code:
public class BalloonThrowerHealth : MonoBehaviour { public int health; Animator myAnimator; public GameObject dummyBalloon; Image soakBar; public Transform soakImage; public GameObject soakPoint; Image wetBar; public Transform wetImage; Image healthBar; public Transform barImage; public Transform player; int test; void Start() { } private void Awake() { myAnimator = GetComponent<Animator>(); wetBar = GameObject.Find("wet").GetComponent<Image>(); soakBar = GameObject.Find("BalloonEnemyDry").GetComponent<Image>(); healthBar = GameObject.Find("BalloonHealthBar").GetComponent<Image>(); soakPoint.SetActive(true); test = 1500; } public void DoDamage(int damageAmount) { health = health - damageAmount; print("enemy health is" + health); test = test - damageAmount; switch(test) { case 1500: soakBar.GetComponent<RectTransform>().sizeDelta = new Vector3(100f, 100f); break; case 1400: soakBar.GetComponent<RectTransform>().sizeDelta = new Vector3(93.34f, 100f); break; case 1300: soakBar.GetComponent<RectTransform>().sizeDelta = new Vector3(86.68f, 100f); break; case 1200: soakBar.GetComponent<RectTransform>().sizeDelta = new Vector3(80.02f, 100f); break; case 1100: soakBar.GetComponent<RectTransform>().sizeDelta = new Vector3(73.36f, 100f); break; case 1000: soakBar.GetComponent<RectTransform>().sizeDelta = new Vector3(66.7f, 100f); break; case 900: soakBar.GetComponent<RectTransform>().sizeDelta = new Vector3(60.04f, 100f); break; case 800: soakBar.GetComponent<RectTransform>().sizeDelta = new Vector3(53.38f, 100f); break; case 700: soakBar.GetComponent<RectTransform>().sizeDelta = new Vector3(46.72f, 100f); break; case 600: soakBar.GetComponent<RectTransform>().sizeDelta = new Vector3(40.06f, 100f); break; case 500: soakBar.GetComponent<RectTransform>().sizeDelta = new Vector3(33.4f, 100f); break; case 400: soakBar.GetComponent<RectTransform>().sizeDelta = new Vector3(26.74f, 100f); break; case 300: soakBar.GetComponent<RectTransform>().sizeDelta = new Vector3(20.08f, 100f); break; case 200: soakBar.GetComponent<RectTransform>().sizeDelta = new Vector3(13.42f, 100f); break; case 100: soakBar.GetComponent<RectTransform>().sizeDelta = new Vector3(6.76f, 100f); break; case 0: soakBar.GetComponent<RectTransform>().sizeDelta = new Vector3(0f, 1000f); break; } if(health <= 0 && test <= 0) { dummyBalloon.SetActive(false); myAnimator.SetTrigger("gotSoaked"); soakPoint.SetActive(false); Destroy(GetComponent<BallonThrowAI>()); Destroy(GetComponent<Collider>()); } } private void Update() { barImage.LookAt(player); soakImage.LookAt(player); wetImage.LookAt(player); }
Comment