Exemple #1
0
    void Start()
    {
        if (GameController.mapIsDone == true)
        {
            TM = GameObject.FindGameObjectWithTag("TileMap").GetComponent <TileMap>();
            //Get the loaded enemylist from resources
            EnemyList eList = EnemyList.GetEnemyList();

            // Randomise enemies
            EnemyControl.Randomise();
            if (eList != null)
            {
                GameObject SelectedModel = eList.GetRelevantModel(EnemyControl.enemyClass);
                if (SelectedModel != null)
                {
                    Vector3 NewPos = transform.position + transform.up * (transform.lossyScale.y * 0.5f);
                    selectedEnemy = GameObject.Instantiate(SelectedModel, NewPos, transform.rotation) as GameObject;

                    if (selectedEnemy != null)
                    {
                        if (selectedEnemy.GetComponent <EnemyUnit>() != null)
                        {
                            selectedEnemy.GetComponent <EnemyUnit>().map = TM;
                            float PositionOffset = TM.tileSize / 2.0f;
                            selectedEnemy.GetComponent <EnemyUnit>().SetSpawnLocation((int)((NewPos.x - PositionOffset) / TM.tileSize), (int)((NewPos.z - PositionOffset) / TM.tileSize));
                        } //if
                    }     //if
                }         //if
            }             //if
        }                 //if
    }                     //Start
Exemple #2
0
 public override void FindTarget()
 {
     target    = null;
     tDistance = Vector2.Distance(transform.position, gameObject.transform.position);
     foreach (Enemy temp in el.GetEnemyList())
     {
         if (temp.pDistance < detection)             // if the enemy is inside the aggro range
         {
             if (temp.cDistance < tDistance)         // if they are the closest to the companion
             {
                 target    = temp;
                 tDistance = temp.cDistance;
             }
         }
     }
     if (target)
     {
         tDistance = Vector2.Distance(transform.position, target.gameObject.transform.position);
     }
 }
    public override void FindTarget()
    {
        eDistance = 100;
        pDistance = Vector2.Distance(transform.position, p.gameObject.transform.position);
        target    = p;
        if (pDistance > 15)         // get the the choppa! or to the player, w/e
        {
            gameObject.transform.position = p.gameObject.transform.position;
            tDistance = pDistance;
            return;
        }
        if (pDistance > 10)         // get the the choppa! or to the player, w/e
        {
            tDistance = pDistance;
            return;
        }
        foreach (Enemy temp in el.GetEnemyList())
        {
            if (temp.pDistance < p.detection - temp.stealth)    // if the enemy is inside the aggro range
            {
                if (temp.cDistance < eDistance)                 // if they are the closest to the companion
                {
                    target    = temp;
                    eDistance = temp.cDistance;
                }
            }
        }
        if (target == p)
        {
            tDistance = pDistance;
        }
        else
        {
            tDistance = eDistance;
        }

        sightRange = detection - target.stealth;
    }