Exemplo n.º 1
0
    private void FixedUpdate()
    {
        if (UnitStatus.health < 0.0f && !isDeath)
        {
            animator.SetTrigger("Death");
            isDeath = true;
        }

        HUD.HpApply(UnitStatus.health, UnitStatus.Maxhealth);
        if (isDeath)
        {
            return;
        }

        TargetTracking();

        if (Target && !Target.GetComponent <Units>().isDeath)
        {
            float dist = Vector3.Distance(this.transform.position, Target.transform.position);
            if (dist <= minionSiegeData.UnitSight.attackRange &&
                (animator.GetCurrentAnimatorStateInfo(0).IsName("Run") ||
                 animator.GetCurrentAnimatorStateInfo(0).IsName("Idle")))
            {
                agent.isStopped = true;
                animator.SetBool("attack", true);
                animator.SetBool("run", false);

                Vector3 dest = Target.transform.position - this.transform.position;
                dest.Normalize();
                this.transform.rotation = Quaternion.LookRotation(dest);
            }
            else if (dist <= minionSiegeData.UnitSight.attackRange)
            {
                Vector3 dest = Target.transform.position - this.transform.position;
                dest.Normalize();
                this.transform.rotation = Quaternion.LookRotation(dest);
            }
            else if (dist > minionSiegeData.UnitSight.attackRange)
            {
                Target = null;
                animator.SetBool("attack", false);
                animator.SetBool("run", true);

                if (agent.isStopped)
                {
                    agent.isStopped = false;
                }
            }
        }
        else if (Target && Target.GetComponent <Units>().isDeath)
        {
            Target = null;
        }

        if (elapsedSearchTime >= 0.0f)
        {
            elapsedSearchTime -= Time.deltaTime;
            elapsedSearchTime  = elapsedSearchTime < 0.0f ? 0.0f : elapsedSearchTime;
        }
    }
Exemplo n.º 2
0
    private void FixedUpdate()
    {
        if (UnitStatus.health < 0.0f && !isDeath)
        {
            const int DeathAnimaton = 4;
            animator.SetInteger("death", Random.Range(0, DeathAnimaton));
            isDeath = true;
        }

        if (isDeath)
        {
            return;
        }

        HUD.HpApply(UnitStatus.health, UnitStatus.Maxhealth);

        TargetTracking();

        if (Target && !Target.GetComponent <Units>().isDeath)
        {
            float dist = Vector3.Distance(this.transform.position, Target.transform.position);
            if (dist <= minionMeleeData.UnitSight.attackRange &&
                (animator.GetCurrentAnimatorStateInfo(0).IsName("Run") ||
                 animator.GetCurrentAnimatorStateInfo(0).IsName("Idle")))
            {
                agent.isStopped = true;
                StartCoroutine("AttackAnim");
                animator.SetBool("attack", true);
                animator.SetBool("run", false);

                Vector3 dest = Target.transform.position - this.transform.position;
                dest.Normalize();
                this.transform.rotation = Quaternion.LookRotation(dest);
            }
            else if (dist > minionMeleeData.UnitSight.attackRange)
            {
                StopCoroutine("AttackAnim");
                animator.SetBool("attack", false);
                animator.SetBool("run", true);

                agent.SetDestination(Target.transform.position);
                Target = null;

                if (agent.isStopped)
                {
                    agent.isStopped = false;
                }
            }
        }
        else if (Target && Target.GetComponent <Units>().isDeath)
        {
            Target = null;
        }
    }