private void HitObject(Collider other) { // Debug.Log(other.gameObject.layer.ToString()); if (other.gameObject.GetComponentInParent <DamageableEntity>() != null) { //Debug.Log($"1: {this.transform.gameObject.name} -> {other.transform.parent.gameObject.name}"); other.GetComponentInParent <DamageableEntity>().TakeDamage(bulletDamage, allegiance); SchematicShowHit ssh = other.transform.root.gameObject.GetComponentInChildren <SchematicShowHit>(); if (ssh != null) { ssh.ShowHit(this.transform.position); } Die(); } else //if (other.gameObject.layer.ToString() != "8") { //Debug.Log($"2: {this.transform.gameObject.name} -> {other.transform.gameObject.name}"); Die(); } }
/* * private void OnTriggerEnter(Collider other) * { * Debug.Log($"Missile colliding with {other.transform.gameObject.name}"); * if (other.transform.gameObject.GetComponentInParent<DamageableEntity>() != null) * { * //Debug.Log($"1: {this.transform.gameObject.name} -> {other.transform.parent.gameObject.name}"); * other.transform.GetComponentInParent<DamageableEntity>().TakeDamage(missileDamage, allegiance); * Destroy(this.gameObject); * } * }*/ private void OnCollisionEnter(Collision collision) { //Debug.Log($"Missile colliding with {collision.transform.gameObject.name}"); if (collision.transform.gameObject.GetComponentInParent <DamageableEntity>() != null) { FindObjectOfType <AudioManager>().PlayExplosion(); //Debug.Log($"1: {this.transform.gameObject.name} -> {other.transform.parent.gameObject.name}"); collision.transform.GetComponentInParent <DamageableEntity>().TakeDamage(missileDamage, allegiance); // hurt player this.GetComponent <DamageableEntity>().TakeDamage(missileDamage, EAllegiance.Player); // kill missile SchematicShowHit ssh = collision.gameObject.transform.root.gameObject.GetComponentInChildren <SchematicShowHit>(); if (ssh != null) { ssh.ShowHit(this.transform.position); } //Destroy(this.gameObject); } else //if (collision.transform.gameObject.layer.ToString() != "8") { //Debug.Log($"2: {this.transform.gameObject.name} -> {other.transform.gameObject.name}"); //Destroy(this.gameObject); } }