public void takeDamage(int damage) { if (invincible == false) { if (hitSound != null && audioSource.isPlaying == false) { audioSource.PlayOneShot(hitSound); } gameObject.GetComponent <Renderer>().material.color = Color.red; health -= damage; time = 0.0f; scr_hpsystem parent = gameObject.GetComponentInParent <scr_hpsystem>(); if (parent != this) { parent.takeDamage(damage); } } }
// Use this for initialization void Start() { hp = GetComponentInParent <scr_hpsystem>(); hp.health = 3; }