예제 #1
0
    /*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);
    }
예제 #2
0
    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);
    }
예제 #3
0
 public virtual void Start()
 {
     damagableBehaviour = GetComponent <DamagableBehaviour>();
 }