Example #1
0
    void Start()
    {
        deadGoblin         = false;
        transform.position = points[0].position;
        currentPoint       = 0;

        if (transform.localScale.x == 2)
        {
            currentState = GoblinEnemyState.patrol;
            animator     = GetComponent <Animator>();
            target       = GameObject.FindGameObjectWithTag("Player").transform;
            health       = 30;
            attackHit    = 2;
            speed        = 1f;

            rb2d = GetComponent <Rigidbody2D>();

            chaseRadious  = 30;
            attackRadious = 4f;
        }
        else if (transform.localScale.x == 0.5f)
        {
            currentState = GoblinEnemyState.patrol;
            animator     = GetComponent <Animator>();
            target       = GameObject.FindGameObjectWithTag("Player").transform;
            health       = 3;
            attackHit    = 1;
            speed        = 3f;

            rb2d = GetComponent <Rigidbody2D>();

            chaseRadious  = 10;
            attackRadious = 1f;
        }
    }
Example #2
0
 private void changeState(GoblinEnemyState newState)
 {
     if (currentState != newState)
     {
         currentState = newState;
     }
 }
Example #3
0
    private IEnumerator KnockWithoutDamage(Rigidbody2D hit)
    {
        if (hit != null)
        {
            yield return(new WaitForSeconds(0.2f));

            hit.velocity = Vector2.zero;

            yield return(new WaitForSeconds(0.2f));

            currentState = GoblinEnemyState.patrol;
        }
    }
Example #4
0
    private IEnumerator Knock(Rigidbody2D hit, int attackPower)
    {
        if (hit != null)
        {
            decreaseHealth(attackPower);

            yield return(new WaitForSeconds(0.2f));

            hit.velocity = Vector2.zero;

            yield return(new WaitForSeconds(0.2f));

            currentState = GoblinEnemyState.patrol;
        }
    }
Example #5
0
    void checkDistance()
    {
        if (target != null && target.GetComponent <PlayerHealth>().health > 0)
        {
            if (Vector3.Distance(target.position, transform.position) <= chaseRadious && Vector3.Distance(target.position, transform.position) > attackRadious)
            {
                if (currentState == GoblinEnemyState.patrol && currentState != GoblinEnemyState.stagger)
                {
                    Vector3 temp = Vector3.MoveTowards(transform.position, target.position, speed * Time.deltaTime);
                    rb2d.MovePosition(temp);
                    SetAnimatorsFloats(temp - transform.position);
                    currentState = GoblinEnemyState.patrol;
                }
            }
            else if (Vector3.Distance(target.position, transform.position) <= attackRadious)
            {
                rb2d.velocity = Vector2.zero;
                StartCoroutine(Attack());
            }
            else if (Vector3.Distance(target.position, transform.position) > chaseRadious && !deadGoblin)
            {
                if (Vector3.Distance(transform.position, points[currentPoint].position) < 0.5f)
                {
                    currentPoint++;
                }

                if (currentPoint >= points.Length)
                {
                    currentPoint = 0;
                }

                Vector3 temp = Vector3.MoveTowards(transform.position, points[currentPoint].position, speed * Time.deltaTime);
                rb2d.MovePosition(temp);
                SetAnimatorsFloats(temp - transform.position);
                changeState(GoblinEnemyState.patrol);
            }
        }
    }