Ejemplo n.º 1
0
    public void SpawnEnemies(int numSpawn, float x, float y, float z, float range = -1)
    {
        npcs       = null;
        numToSpawn = numSpawn;
        npcs       = new NPCUnit[numToSpawn];
        for (int i = 0; i < numToSpawn; i++)
        {
            GameObject go = (GameObject)Instantiate(enemyPrefab);

            go.transform.position = new Vector3(x, y, z);

            NPCMovementController   npc  = go.GetComponent <NPCMovementController>();
            NPCAppearanceController npcA = go.GetComponent <NPCAppearanceController>();

            if (npcA != null)
            {
                npcA.Init();
            }

            if (npc != null)
            {
                //Naming for ease
                npc.gameObject.name = i.ToString("0000");                 //assuming we have less than 10,000
                npcs[i]             = npc.GetComponent <NPCUnit>();

                //Movement update
                if (range > 0)
                {
                    npc.maxDistance            = range;
                    npc.randomPositionGenerate = true;
                }
            }
        }
    }
Ejemplo n.º 2
0
 void Start()
 {
     if (player == null)
     {
         player = GameObject.FindGameObjectWithTag("Player");
     }
     appearancreController = gameObject.GetComponent <NPCAppearanceController> ();
     appearancreController.Init();
 }