Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        timerDamge += Time.deltaTime;
        if (timerDamge >= timerDamageMax)
        {
            if (goal && humanToAttack != null) {
                humanToAttack.takeDamage(this.damage);
                Debug.Log("Human Unit [" + humanToAttack.pv + "/20] has been attacked");
            } else if (goal && buildToAttack != null) {
                buildToAttack.takeDamage(this.damage);
                Debug.Log("Human Buildiing [" + buildToAttack.pv + "/" + buildToAttack.pvMax + "] has been attacked");
            }
            timerDamge = 0;
        }

        if (humanToAttack == null && buildToAttack == null)
            goal = false;

        if (goal)
            anim.SetBool ("attacking", true);
        else
            anim.SetBool("attacking", false);

        if (this.pv <= 0) {
            this.pv = 0;
            anim.SetBool("dead", true);
        } else {
            anim.SetBool("dead", false);
        }

        // goes to position for goal
        if (this.humanToAttack != null && this.goal == false) {
            setDirection(humanToAttack.transform.position);
        } else if(this.buildToAttack != null && goal == false) {
            setDirection(buildToAttack.transform.position);
        }

        // reset target if dead
        if (humanToAttack != null && humanToAttack.pv <= 0) {
            humanToAttack.GetComponent<BoxCollider2D>().size = Vector2.zero;
            humanToAttack = null;
            goal = false;
        }
        if (buildToAttack != null && buildToAttack.pv <= 0) {
            buildToAttack = null;
            goal = false;
        }

        if(!Mathf.Approximately(rb.position.magnitude, direction.magnitude)) {
            gameObject.transform.position = Vector3.Lerp (gameObject.transform.position, direction, 1 / (15.0f * (Vector3.Distance (gameObject.transform.position, direction))));
            if (!goal)
                anim.SetBool ("walking", true);
        } else {
            anim.SetBool ("walking", false);
            transform.localScale = new Vector3(1, 1, 1);
        }
    }
Ejemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        timerDamge += Time.deltaTime;
        if (timerDamge >= timerDamageMax)
        {
            if (goal && humanToAttack != null)
            {
                humanToAttack.takeDamage(this.damage);
                Debug.Log("Human Unit [" + humanToAttack.pv + "/20] has been attacked");
            }
            else if (goal && buildToAttack != null)
            {
                buildToAttack.takeDamage(this.damage);
                Debug.Log("Human Buildiing [" + buildToAttack.pv + "/" + buildToAttack.pvMax + "] has been attacked");
            }
            timerDamge = 0;
        }

        if (humanToAttack == null && buildToAttack == null)
        {
            goal = false;
        }

        if (goal)
        {
            anim.SetBool("attacking", true);
        }
        else
        {
            anim.SetBool("attacking", false);
        }

        if (this.pv <= 0)
        {
            this.pv = 0;
            anim.SetBool("dead", true);
        }
        else
        {
            anim.SetBool("dead", false);
        }

        // goes to position for goal
        if (this.humanToAttack != null && this.goal == false)
        {
            setDirection(humanToAttack.transform.position);
        }
        else if (this.buildToAttack != null && goal == false)
        {
            setDirection(buildToAttack.transform.position);
        }

        // reset target if dead
        if (humanToAttack != null && humanToAttack.pv <= 0)
        {
            humanToAttack.GetComponent <BoxCollider2D>().size = Vector2.zero;
            humanToAttack = null;
            goal          = false;
        }
        if (buildToAttack != null && buildToAttack.pv <= 0)
        {
            buildToAttack = null;
            goal          = false;
        }

        if (!Mathf.Approximately(rb.position.magnitude, direction.magnitude))
        {
            gameObject.transform.position = Vector3.Lerp(gameObject.transform.position, direction, 1 / (15.0f * (Vector3.Distance(gameObject.transform.position, direction))));
            if (!goal)
            {
                anim.SetBool("walking", true);
            }
        }
        else
        {
            anim.SetBool("walking", false);
            transform.localScale = new Vector3(1, 1, 1);
        }
    }