Example #1
0
 public AWeapon(float _fireDelay, GameObject _owner, GameObject _projectilePrefab, Vector3 _bulletDirection)
 {
     owner = _owner;
     fireDelay = _fireDelay;
     projectilePrefab = _projectilePrefab;
     bulletDirection = _bulletDirection;
     ownerScript = owner.GetComponent<AEnemy>();
 }
Example #2
0
    /*
    private methods
    */
    private bool changeTarget()
    {
        int bestTarget = -1; // means no target
        int bestScore = 1000;
        int myX = (int)transform.position.x;
        int myY = (int)transform.position.y;
        Vector2 myPosition = new Vector2(myX, myY);

        // if there is atleast 1 friend, then checking and returning index
        if (!(LevelManager.enemiesSpawned.Count < 1))
        {
            //print("trying to change target");
            // looking for best target
            for (int i = 0; i < LevelManager.enemiesSpawned.Count; i++)
            {

                AEnemy potentialTarget = LevelManager.enemiesSpawned[i];

                Vector2 potentialTargetPosition = new Vector2(
                                                                (int)potentialTarget.transform.position.x,
                                                                    (int)potentialTarget.transform.position.y);

                int score = MapCalc.GetMinCost(myPosition, potentialTargetPosition);

                if (score < bestScore)
                {
                    bestScore = score;
                    bestTarget = i;
                }
            }

            // better to add try catch, cause some of the enemies might try to swap into unexisting char
            try
            {
                _enemyTarget = LevelManager.enemiesSpawned[bestTarget];
            }
            catch (Exception e)
            {
                print("ERROR!" + e.StackTrace);
            }

            return true;
        }

        return false;
    }
Example #3
0
 private void createEnemy(AEnemy enemy, Vector2 pos)
 {
     AEnemy instance = Instantiate(enemy, pos, Quaternion.identity) as AEnemy;
     instance.transform.SetParent(enemyHolder.transform);
     enemiesSpawned.Add(instance);
 }
Example #4
0
    private void createEnemy(AEnemy enemy)
    {
        bool spawned = false;
        int x = 0;// Random.Range(0, MapManager.rows-1);

        int counter = 0;

        while (spawned == false)
        {

            int y = Random.Range(0, MapManager.yRow - 1);

             Vector3 pos = new Vector2(x, y);

            if(Physics2D.OverlapCircleAll(pos, .4f).Length <1)
            {

                createEnemy(enemy, pos);

                spawned = true;
            }

            if (counter > MapManager.yRow)
            {
                spawned = true;
            }
            counter++;

        }
    }