private void OnCollisionEnter(Collision collision) { if (collision.gameObject.CompareTag(tagToDamage)) { HealthService healthSrv = collision.gameObject.GetComponent <HealthService>(); if (healthSrv) { healthSrv.DealDamage(damage); } } }
//public Text healthBar; private void OnCollisionEnter(Collision collision) { Instantiate(hitAnimation, transform.position, transform.rotation); //healthBar.text = (Int64.Parse(healthBar.text) - damage).ToString(); if (collision.gameObject.CompareTag(tagToDamage)) { HealthService healthSrv = collision.gameObject.GetComponent <HealthService>(); if (healthSrv) { healthSrv.DealDamage(damage); } } }