Exemplo n.º 1
0
    public void spawnEnemiesAtNextCheckpoint()
    {
        currentEnemies = new List <GameObject>();


        GameObject      checkpointObj = getNextEnemyCheckpoint();
        EnemyCheckpoint checkpoint    = checkpointObj.GetComponent <EnemyCheckpoint>();

        List <Transform>  spawns        = checkpoint.GetSpawnLocationsAtCheckpoint();
        List <GameObject> asleepEnemies = getNonActiveEnemies();

        foreach (Transform spawn in spawns)
        {
            GameObject enemy = Instantiate(enemies[0]);

            enemy.GetComponent <EnemyController>().SetupEnemy(spawn);
            currentEnemies.Add(enemy);
            asleepEnemies.RemoveAt(0);
        }

        enemiesLeft = currentEnemies.Count;
    }
Exemplo n.º 2
0
    /// <summary>
    /// Sets the target..
    /// </summary>
    void Update()
    {
        if (_characterStatus.IsInvulnerable)
        {
            return;
        }

        #region Found Player

        if (_targetSelector.CurrentTarget != null)
        {
            Vector3 targetPos  = _targetSelector.CurrentTarget.transform.position;
            Vector3 entityPos  = transform.position;
            Vector3 difference = (targetPos - entityPos);
            float   distance   = difference.sqrMagnitude;


            if (distance > ShootingDistance)
            {
                _agent.destination = _targetSelector.CurrentTarget.transform.position;
                _running           = false;
            }
            else if (distance < PanicDistance || _running)
            {
                _agent.destination = entityPos - difference;
                _running           = true;
            }
            else if (!_running)
            {
                // Lookat and shoot.
                _agent.destination = entityPos;
                transform.LookAt(targetPos);

                if (!_cooldown)
                {
                    Fire();
                    StartCoroutine(Cooldown());
                }
            }
        }
        else
        {
            #region Follow Path

            if (_currentCheckpoint == null)
            {
                _currentCheckpoint = WaypointManager.GetCheckpoint(_currentOrder);
            }

            if (_currentCheckpoint != null)
            {
                _agent.destination = _currentCheckpoint.Position;

                if ((_currentCheckpoint.Position - transform.position).magnitude < 0.1)
                {
                    _currentOrder++;
                    _currentCheckpoint = null;
                }
            }
            else
            {
                // If Checkpoint was null, it doesn't exist.
                _currentOrder = 0;
            }

            #endregion Follow Path
        }

        #endregion Found Player



        #region Animation
        if (Animator != null)
        {
            Animator.SetFloat("Speed", _agent.speed);
        }
        #endregion Animation
    }
Exemplo n.º 3
0
 public static void RegisterWaypoint(EnemyCheckpoint checkpoint)
 {
     Instance._waypoints.Add(checkpoint);
 }