PlayerAttack.Attack C# (CSharp) Method

Attack() private method

private Attack ( ) : void
return void
    private void Attack()
    {
        float distance = Vector3.Distance(target.transform.position,
            transform.position);

        Vector3 dir = (target.transform.position - transform.position).normalized;

        float direction = Vector3.Dot(dir, transform.forward);

        Debug.Log(direction);

        if (distance < 2.5f)
        {
            if (direction > 0)
            {
                EnemyHealth enemyHealth = (EnemyHealth)target.GetComponent("EnemyHealth");

                enemyHealth.AdjustHealth(-10);
            }
        }
    }

Usage Example

Example #1
0
 private void OnTriggerEnter(Collider other)
 {
     if (transform.parent.CompareTag("Human"))
     {
         playerAttack.Attack(other.gameObject);
     }
     //if (transform.parent.CompareTag("Mosquito"))
     //{
     //    Debug.Log("other: " + other);
     //    playerAttack.Attack(other.gameObject);
     //}
 }
All Usage Examples Of PlayerAttack::Attack