Exemplo n.º 1
0
    public void Attack()
    {
        float distance = float.MaxValue;

        if (targets == null)
        {
            return;
        }

        foreach (GameObject target in targets)
        {
            if (target != null)
            {
                distance = Vector3.Distance(target.transform.position, transform.position);

                if (distance < 5.0f)
                {
                    EnemyHealth eh = (EnemyHealth)target.GetComponent("EnemyHealth");
                    if (eh != null)
                    {
                        eh.AdjustCurrentHealth(-45);
                    }
                }
            }
        }
    }
Exemplo n.º 2
0
    private void Attack()
    {
        //To check how far the player is from the enemy
        if (target == null)
        {
        }
        else
        {
            float distance = Vector3.Distance(target.transform.position, transform.position);

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

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

            //checker to see our distance from the enemy and direction
            //Debug.Log(distance);
            Debug.Log(direction);

            if (distance <= 2)
            {
                if (direction > 0)
                {
                    EnemyHealth eh = (EnemyHealth)target.GetComponent("EnemyHealth");
                    eh.AdjustCurrentHealth(-35);
                }
            }
        }
    }
Exemplo n.º 3
0
    private void Attack()
    {
        float distance = Vector3.Distance(target.transform.position, transform.position);

        //set direction and move one unit forward
        Vector3 dir       = (target.transform.position - transform.position).normalized;
        float   direction = Vector3.Dot(dir, transform.forward);

        //call new instance of Enemny health
        EnemyHealth eh = (EnemyHealth)target.GetComponent("EnemyHealth");

        //Debug.Log(distance);

        //should return between 1 and -1, 1 is in front, -1 is behind

        //Debug.Log(direction);


        if (distance <= 2.5f)
        {
            if (direction > 0)
            {
                eh.AdjustCurrentHealth(-10);
            }
        }
    }
Exemplo n.º 4
0
    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);

        if (distance < 2.5f && direction > 0)
        {
            EnemyHealth eh = (EnemyHealth)target.GetComponent("EnemyHealth");
            eh.AdjustCurrentHealth(-10);
            attackTimer = coolDown;
        }
    }
Exemplo n.º 5
0
    private void Attack()
    {
        float distance = Vector3.Distance(target.transform.position, transform.position);         // defines the distance the player can hit the enemy

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

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

        Debug.Log(distance);        // to measure distance in console for defining distances
        if (distance < 10)          // max distance the player can be from enemy to hit
        {
            if (direction > 0)      // makes sure player is facing enemy to hit

            {
                EnemyHealth eh = (EnemyHealth)target.GetComponent("EnemyHealth");
                eh.AdjustCurrentHealth(-10);                 // enemy loses 10 health for each attack it is hit by
            }
        }
    }
Exemplo n.º 6
0
    // Attack
    private void Attack()
    {
        // distance between the target and the player
        float distance = Vector3.Distance(target.transform.position, transform.position);

        // check where enemy is wrt the player
        // dot product returns value between 1 and -1. 1 means enemy is in front of us, -1 he's to the back
        Vector3 dir       = (target.transform.position - transform.position).normalized;
        float   direction = Vector3.Dot(dir, transform.forward);

        Debug.Log(direction);


        if (distance < 2.5f)         // check if close enough for attack to hit
        {
            if (direction > 0)       // check whether enemy is in front of us
            {
                // ref to EnemyHealth script of target and do damage
                EnemyHealth eh = (EnemyHealth)target.GetComponent("EnemyHealth");
                eh.AdjustCurrentHealth(-10);
            }
        }
    }