void OnCollisionEnter2D(Collision2D collision) { GameObject collGO = collision.collider.gameObject; //Debug.Log("Collided with " + collGO.name); if (collGO.CompareTag("Target")) { if (collGO.name == "Player_Unit") { collGO.GetComponent <PlayerHealth>().doColliderHit(); GameManager.damagePlayer(damageValue); } else { SupportStructure sStruct = collGO.GetComponent <SupportStructure>(); sStruct.Health -= damageValue; } DoCollisionDestroy(); } else if (collGO.CompareTag("Bullet")) { int Damage = collGO.GetComponent <Projectile>().damageValue; Health -= Damage; Destroy(collGO); } }
/// <summary> /// Sent each frame where a collider on another object is touching /// this object's collider (2D physics only). /// </summary> /// <param name="other">The Collision2D data associated with this collision.</param> void OnCollisionStay2D(Collision2D other) { SupportStructure sS = other.collider.GetComponent <SupportStructure>(); if (other.collider.name == "Player_Unit") { GameManager.damagePlayer(Damage); other.collider.gameObject.GetComponent <PlayerHealth>().doColliderHit(); } else if (sS != null) { sS.Health -= Damage; } }
// Use this for initialization void Start() { myHPBar = gameObject.GetComponentInChildren <Slider>(); mySS = gameObject.GetComponent <SupportStructure>(); myHPBar.maxValue = mySS.Health; }