// Gives damage to any tank that the projectile hits public void GiveDamage(Collision reciever, int amount) { GameObject enemyTank = reciever.transform.parent.gameObject; ControllerUniversal enemyScript = enemyTank.GetComponent <ControllerUniversal>(); if (enemyScript != null) { enemyScript.TakeDamage(amount); } }
void OnCollisionEnter(Collision agentCollider) { if (agentCollider.gameObject != shootingTank) { if (agentCollider.gameObject.tag == "Tank") { ControllerUniversal tankScript = agentCollider.gameObject.GetComponent <ControllerUniversal>(); tankScript.GiveDamage(agentCollider, attackDamage); } Destroy(gameObject); } }
private void Start() { tcu = gameObject.GetComponent <ControllerUniversal>(); }