Ejemplo n.º 1
0
 private void SetDamage(IDamageble obj)
 {
     if (obj != null)
     {
         obj.TakeDamage(_damage);
         Destroy(gameObject);
     }
 }
    void OnTriggerEnter2D(Collider2D other)
    {
        PlayerController player = other.GetComponent <PlayerController>();

        if (player != null)
        {
            IDamageble targetDamage = other.GetComponent <IDamageble>();
            if (targetDamage != null)
            {
                targetDamage.TakeDamage(hitter, damage, false);
            }
        }
    }
Ejemplo n.º 3
0
    public void Shooting(Vector3 _origin, Vector3 _dir, Vector3 _startBuiletPosition, float _range, GameObject _builetPref, float _damage, float _speed)
    {
        RaycastHit _hit;

        if (Physics.Raycast(_origin, _dir, out _hit, _range))
        {
            GameObject outBuilett = GameObject.Instantiate(_builetPref, _startBuiletPosition, Quaternion.identity);
            outBuilett.GetComponent <Rigidbody>().AddForce(_current.transform.forward * _speed);
            IDamageble dmg = _hit.transform.GetComponent <IDamageble>();
            if (dmg != null)
            {
                dmg.TakeDamage(_damage);
            }
        }
    }
Ejemplo n.º 4
0
    //this is for the bullet which is inside a collider and still destroying the gameObject.

    void OnHiObject(Collider c)
    {
        //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 = c.GetComponent <IDamageble>();

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

        GameObject.Destroy(gameObject);
    }
Ejemplo n.º 5
0
    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.isTrigger == true)
        {
            return;
        }
        Block block = other.GetComponent <Block>();

        if (weaponType != "PickAxe" && block != null)
        {
            return;
        }
        IDamageble hit = other.GetComponent <IDamageble>();

        Debug.Log("IS CRIT:" + isCritical);
        if (hit != null)
        {
            hit.TakeDamage(GameSession.instance.Player.gameObject, damage, isCritical);
        }
    }