Exemple #1
0
    void FixedUpdate()
    {
        if (target == null)
        {
            if (!searchingForPlayer)
            {
                searchingForPlayer = true;
                StartCoroutine(SearchForPlayer());
            }
            return;
        }

        if (path == null)
        {
            return;
        }
        if (currentWaypoint >= path.vectorPath.Count)
        {
            if (pathIsEnded)
            {
                return;
            }
            Debug.Log("End of path reached");
            pathIsEnded = true;
            return;
        }

        if (target != null)
        {
            pathIsEnded = false;
            lookAtPlayer();
            //find direction to next waypoint
            Vector2 direction = (path.vectorPath [currentWaypoint] - transform.position).normalized;
            direction *= speed * Time.deltaTime;

            //move the ai
            enemyRigidbody.AddForce(direction, fMode);

            float curWayPointDist = Vector2.Distance(transform.position, path.vectorPath [currentWaypoint]);

            playerDistance = Vector2.Distance(target.position, transform.position);

            if (curWayPointDist < nextWaypointDist && playerDistance > 1f)
            {
                currentWaypoint++;
                return;
            }

            if (playerDistance <= 10f)
            {
                if (PlayerHiddenByObstacles() == false)
                {
                    enemyShooting.isShooting(enemyShooting.lengthOfBurst);
                    enemyShooting.burstTime = 0;
                    anim.SetBool("isWalking", true);
                    //Debug.Log ("Player in sight");
                }
            }
        }
    }