예제 #1
0
 public void SetAttackOrder(GameObject enemy)
 {
     attack_target = enemy.GetComponent <enemy_controller>();
     //move to the enemy minus the attack range and a percentage
     move_Script.MoveTo(enemy.transform.position, GetAttackRange() / 100.0f - (GetAttackRange() / 100.0f) * 0.10f);
     //rotate towards the target
     transform.rotation    = Quaternion.LookRotation(new Vector3(attack_target.GetPosition().x, transform.position.y, attack_target.GetPosition().z));
     transform.eulerAngles = new Vector3(0, transform.eulerAngles.y, 0);
 }
예제 #2
0
    private void attemptAbilityFire(int index)
    {
        Ability ability = main_unit.GetComponent <unit_control_script>().GetAbility(index);

        if (ability.GetLevel() < 1)
        {
            return;
        }
        if (main_unit.GetMana() < ability.GetCost() || ability.OnCooldown())
        {
            return;
        }
        //if the ability is a point target spell see if there is a target under neath the player and that the enemy is in range
        if (ability.ActivationType == AbilityActivationType.Cast)
        {
            if (ability._TargetType == TargetType.PointTarget)
            {
                //see if there is an enemy under the player cursor
                RaycastHit hit;
                if (Physics.Raycast(GameObject.FindObjectOfType <Camera>().ScreenPointToRay(Input.mousePosition), out hit))
                {
                    enemy_controller enemy = hit.transform.gameObject.GetComponent <enemy_controller>();
                    if (hit.transform.CompareTag("Enemy") && UtilityHelper.InRange(main_unit.GetPosition(), enemy.GetPosition(), (ability.GetCastRange() + main_unit.GetCastRange()) / 100.0f))
                    {
                        ability.ActivateAbility(hit.transform.gameObject);
                        //reduce the players mana
                        main_unit.AddMana(-ability.GetCost());
                    }
                }
            }

            if (ability._TargetType == TargetType.Self)
            {
                //check to see if ability is on cooldown
                if (!ability.OnCooldown())
                {
                    ability.ActivateAbility();
                }
            }
        }
    }
예제 #3
0
    // Update is called once per frame
    void Update()
    {
        if (is_dead)
        {
            return;
        }
        move_Script.CorrectRotation();

        //check to see if we are dead
        if (hp < 1)
        {
            if (can_die)
            {
                hp      = 0;
                is_dead = true;
                Assets.Scripts.unit.GraveStone grave = Instantiate(GraveStone).GetComponent <Assets.Scripts.unit.GraveStone>();
                grave.SetOwner(this);
                //disable renderer
                GetComponent <MeshRenderer>().enabled = false;
            }
            else
            {
                hp = 1.001f;
            }
        }

        if (can_heal)
        {
            hp += (added_hp_regen + hp_regen) * Time.deltaTime;
        }
        if (hp > max_hp)
        {
            hp = max_hp;
        }

        //regen mana
        mana += (mana_regen + added_mana_regen) * Time.deltaTime;
        if (mana > max_mana)
        {
            mana = max_mana;
        }


        //check to see if we can attack the enemy
        if (attack_target != null && !attack_target.IsDead() && Vector3.Distance(attack_target.transform.position, transform.position) < GetAttackRange() / 100.0f)
        {
            windup               -= Time.deltaTime;
            transform.rotation    = Quaternion.LookRotation(new Vector3(attack_target.GetPosition().x, attack_target.GetPosition().z));
            transform.eulerAngles = new Vector3(0, transform.eulerAngles.y, 0);
            if (!can_attack)
            {
                ResetWindup();
            }
        }
        else
        {
            //reset windup
            ResetWindup();
        }

        if (windup <= 0 && can_attack)
        {
            //attack the enemy target
            AttackEnemy();
        }
    }