Пример #1
0
    //This version of attack is called by the player
    public void Attack(RaycastHit newTarget)
    {
        if (health <= 0)
        {
            Debug.Log("Dead Characters can't attack");
            return;
        }
        if (energy < attackCost)
        {
            Debug.Log("This character does not have enough energy to attack.");
            return;
        }
        GameObject       attTarget        = GameObject.Find(newTarget.transform.name);
        CharacterDetails targetController = attTarget.GetComponent <CharacterDetails>();
        Rigidbody        targetBody       = attTarget.GetComponent <Rigidbody>();
        float            distance         = Vector3.Distance(characterBody.position, targetBody.position);

        if (distance > range)
        {
            Debug.Log("Target is out of attack range");
            return;
        }

        energy -= attackCost;
        anim.SetTrigger("IsAttacking");
        targetController.TakeDamage(power);
    }
Пример #2
0
    //This version of attack is called by a Strategy
    public int Attack(GameObject target)
    {
        if (health <= 0)
        {
            Debug.Log("Dead Characters can't attack");
            return(-1);
        }
        if (energy < attackCost)
        {
            Debug.Log("This character does not have enough energy to attack.");
            return(-2);
        }
        CharacterDetails targetController = target.GetComponent <CharacterDetails>();
        Rigidbody        targetBody       = target.GetComponent <Rigidbody>();
        float            distance         = Vector3.Distance(characterBody.position, targetBody.position);

        if (distance > range)
        {
            Debug.Log("Target is out of attack range");
            return(-3);
        }

        energy -= attackCost;
        anim.SetTrigger("IsAttacking");
        targetController.TakeDamage(power);

        return(1);
    }