Example #1
0
    // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
    override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        boss.LookAtPlayer();
        Vector2 target;

        if (boss.towardsPlayer)
        {
            target = new Vector2(player.position.x, rb.position.y);
        }
        else
        {
            target = new Vector2(boss.centerPoint.position.x, rb.position.y);
        }

        Vector2 newPos = Vector2.MoveTowards(rb.position, target, boss.stats.moveSpeed * Time.fixedDeltaTime);

        rb.MovePosition(newPos);

        if (boss.towardsPlayer)
        {
            //Check distance to Player
            if (Vector2.Distance(player.position, rb.position) <= boss.stats.nextWaypointDistance)
            {
                animator.SetTrigger("ToAttack");
            }
        }
        else
        {
            //Check distance to Center
            if (Vector2.Distance(boss.centerPoint.position, rb.position) <= 0.5f)
            {
                animator.SetTrigger("ToHeal");
            }
        }
    }
Example #2
0
    // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
    override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        Vector2 target = new Vector2(wallTarget.position.x, rb.position.y);
        Vector2 newPos = Vector2.MoveTowards(rb.position, target, boss.stats.moveSpeed * Time.fixedDeltaTime);

        if (boss.backing)
        {
            rb.MovePosition(newPos);


            //Check distance to target Point
            if (Vector2.Distance(wallTarget.position, rb.position) <= boss.stats.nextWaypointDistance)
            {
                animator.SetTrigger("FinishAttack");
            }
        }
        else
        {
            boss.LookAtPlayer();
        }
    }