コード例 #1
0
    private void TryHit(DamageController damageController)
    {
        if (canAttack)
        {
            damageController.DealDamage(strength);
            animator?.SetBool("Attack", true);

            canAttack = false;
            Invoke("ResetCanAttack", coolDown);
        }
    }
コード例 #2
0
    void OnTriggerEnter(Collider collider)
    {
        // do not collide with own spawner
        if (collider.gameObject.GetInstanceID() == spawningGameObjectId)
        {
            //Debug.Log("Projectile collided with own spawner...");
            return;
        }

        // prevent friendly fire, i.e. only damage enemies
        if (collider.gameObject.CompareTag("Enemy"))
        {
            //Debug.Log("Projectile collided with enemy!");
            DamageController damageController = collider.gameObject.GetComponent <DamageController>();

            if (damageController)
            {
                damageController.DealDamage(damage);
            }
        }

        Destroy(gameObject);
    }