示例#1
0
    // Update is called once per frame
    void Update()
    {
        _Distance = Vector3.Distance(transform.position, _Player.value.position); //getting distance from player
        if (!_NavMesh.enabled)
        {
            return;
        }
        if (_EnemyList.EnemiesOutside.Count > 0)
        {
            _DegreesOfSeparationOutside = _EnemyList.OutsideMaxAngleEnemies / _EnemyList.EnemiesOutside.Count;                                            //getting degrees of separation
        }
        if (_EnemyList.EnemiesInside.Count > 0)
        {
            _DegreesOfSeparationInsside = _EnemyList.InsideMaxAngleEnemies / _EnemyList.EnemiesInside.Count;
        }

        if (_EnemyList.EnemiesInside.Count < _EnemyList.MaxiumEnemiesInside)
        {
            _EnemyList.RegisterEnemiesInside(gameObject);
        }
        else if (!_EnemyList.EnemiesOutside.Contains(gameObject) && !_EnemyList.EnemiesInside.Contains(gameObject))
        {
            _EnemyList.RegisterEnemiesOutside(gameObject);
        }

        MoveToPlayer();
    }
示例#2
0
    private void Update()
    {
        if (_TimeBetweenChange > 0)
        {
            _TimeBetweenChange -= Time.deltaTime;  //decreasing the timer
        }

        if (_EnemyList.EnemiesInside.Count <= 0)
        {
            return;                                      //if there are enemies around the player
        }
        if (_TimeBetweenChange <= 0)
        {
            _EnemyList.RegisterEnemiesOutside(_EnemyList.EnemiesInside[0].gameObject); //moves the enemy back
            _TimeBetweenChange = _MaxTimeBetweenChange;                                //reset the timer
            _EnemyIndex        = Random.Range(0, _EnemyList.EnemiesOutside.Count);     //gets another enemy
            if (_EnemyList.EnemiesOutside.Count > 0)
            {
                _EnemyList.RegisterEnemiesInside(_EnemyList.EnemiesOutside[_EnemyIndex].gameObject); //moves the enemy in
            }
        }
    }