Example #1
0
    void OnHitObject(Collider c, Vector3 hitPoint)
    {
        IDamageble damagebleObject = c.GetComponent <Collider>().GetComponent <IDamageble>();

        if (damagebleObject != null)
        {
            damagebleObject.TakeHit(damage, hitPoint, transform.forward);
        }
        Destroy(gameObject);
    }
    //here we are destroying the bullet and getting a return info of whether a bullet is hit or not.
    void OnHitCheck(RaycastHit hit)
    {
        //here first we are calling the IDamageble script
        //and then on what ever with the hit HITS it is checking if the hitted object having the IDamageble so it can call the TakeHit method.
        //since TakeHit is the method that allows the projectile to destroy.
        IDamageble damageObject = hit.collider.GetComponent <IDamageble>();

        if (damageObject != null)
        {
            float damage = 1;
            damageObject.TakeHit(damage, hit);
        }
        //print(hit.collider.gameObject.name);

        GameObject.Destroy(gameObject);
    }