예제 #1
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        health healthComponent = collision.gameObject.GetComponent <health>();

        if (healthComponent)
        {
            healthComponent.Damage(damage_);
        }
    }
예제 #2
0
    void OnCollisionEnter(Collision collision)
    {
        Debug.Log("collision");
        GameObject obj        = collision.gameObject;
        health     obj_health = obj.GetComponent <health>();

        if (obj_health != null)
        {
            Debug.Log("damaging an object");
            obj_health.Damage(damage);
        }
        Destroy(gameObject);
    }