コード例 #1
0
    private void Attack()      // Enemy has to be facing player and within certain distance to deal damage
    {
        float distance = Vector3.Distance(target.transform.position, transform.position);

        Vector3 dir       = (target.transform.position - transform.position).normalized;
        float   direction = Vector3.Dot(dir, transform.forward);

        if (distance < 2)
        {
            if (direction > 0)
            {
                Player_Health ph = (Player_Health)target.GetComponent("Player_Health");
                ph.AdjustCurrentHealth(-10);
            }
        }
    }