Esempio n. 1
0
    private void Attack(int dmg)
    {
        //Обзор
        if (target == null)
        {
            target = GameObject.FindGameObjectWithTag("Player");
        }
        Vector3 dir = (target.transform.position - transform.position).normalized;
        //Скалярное произведение векторов
        float direction = Vector3.Dot(dir, transform.forward);

        if (Vector3.Distance(target.transform.position, transform.position) <= 1.0f)
        {
            if (direction > 0)
            {
                PlayerHealth ph = (PlayerHealth)target.GetComponent("PlayerHealth");
                ph.AddjustCurrHealth(dmg);
                attackTimer = coolDown;
            }
        }
    }