/*private void Hit(Collision collision) * { * Debug.Log(collision.gameObject.name); * ContactPoint contact = collision.GetContact(0); * GameObject newExp = Instantiate(explosion, contact.point, Quaternion.LookRotation(contact.normal, Vector3.up)) as GameObject; * DamagableBehaviour damagableBehaviour = collision.gameObject.GetComponent<DamagableBehaviour>(); * if (damagableBehaviour != null) * damagableBehaviour.damagable.TakeDamage(damage, DamageType.physical); * Destroy(gameObject); * * }*/ private void Hit(RaycastHit hit) { Debug.Log(hit.collider.gameObject.name); GameObject newExp = Instantiate(explosion, hit.point, Quaternion.LookRotation(hit.normal, Vector3.up)) as GameObject; DamagableBehaviour damagableBehaviour = hit.collider.gameObject.GetComponent <DamagableBehaviour>(); if (damagableBehaviour != null) { damagableBehaviour.damagable.TakeDamage(damage, DamageType.physical); } Destroy(gameObject); }
public void Explode() { Collider[] others = Physics.OverlapSphere(transform.position, explosionRadius); foreach (Collider other in others) { if (other.gameObject.Equals(gameObject)) { continue; } DamagableBehaviour damagableBehaviour = other.GetComponent <DamagableBehaviour>(); if (damagableBehaviour != null) { damagableBehaviour.damagable.TakeDamage(damage, damageType); } } Instantiate(explosion, transform.position, Quaternion.identity); Destroy(gameObject); }
public virtual void Start() { damagableBehaviour = GetComponent <DamagableBehaviour>(); }