public virtual void Move()
    {
        if (Vector3.Distance(transform.position, player.transform.position) >= stoppingDistance)
        {
            agent.SetDestination(player.transform.position);
            animator.SetFloat("Move", currentSpeed / maxSpeed);

            currentSpeed += Time.deltaTime;
            currentSpeed  = Mathf.Clamp(currentSpeed, 0, 5);

            animator.SetBool("Attack", false);
            enemyAttacking.StopAttack();
        }
        else
        {
            agent.SetDestination(transform.position);
            currentSpeed = 0;
            animator.SetFloat("Move", 0);

            enemyAttacking.Attack();

            Vector3 enemyToPlayer = player.transform.position - transform.position;
            enemyToPlayer.y = 0;

            transform.rotation = Quaternion.LookRotation(enemyToPlayer);
        }
    }
Ejemplo n.º 2
0
    void Update()
    {
        bool outOfRange = !enemyAttacking.CheckIfInAttackRange();

        if (!nav.enabled && outOfRange)
        {
            SetNavEnabled(true);
        }

        bool playerAlive = playerHealth.currentHealth > 0,
             mobAlive    = enemyHealth.currentHealth > 0;


        if (mobAlive && playerAlive)
        {
            //Player stealth.
            if (playerMove.isStealth)
            {
                stealthObject = GameObject.FindGameObjectWithTag("Player")
                                .GetComponent <PlayerMovement>()
                                .stealthObject;
                RunAway();
            }
            //Player not stealth.
            else
            {
                if (outOfRange)
                {
                    //Debug.Log("Chasing player.");
                    nav.SetDestination(player.position);
                }
                else
                {
                    SetNavEnabled(false);
                    if (enemyAttacking.CheckIfFacingPlayer())
                    {
                        enemyAttacking.Attack();
                    }
                    else
                    {
                        RotateSlimeTowardsPlayer();
                    }
                    //Debug.Log("Player in range and not stealth");
                }
            }
        }
    }