I am trying to figure out how to spawn enemies using the LayerMask. I am using a procedural map generator and want to spawn enemies on the "Floor" layer tiles at random areas. This is what I have thus far...
using UnityEngine;
using System.Collections;
public class Spawner : MonoBehaviour {
private Vector2 spawnPoint;
public GameObject[] enemies;
public int amount;
void Update()
{
enemies = GameObject.FindGameObjectsWithTag("Enemy1-10");
amount = enemies.Length;
if (amount != 3){
InvokeRepeating("spawnEnemy", 5, 10f);
}
}
void SpawnEnemies(){
spawnPoint.x = LayerMask.NameToLayer("Floor");
spawnPoint.y = LayerMask.NameToLayer("Floor");
Instantiate (enemies [UnityEngine.Random.Range (0, enemies.Length -1)], spawnPoint, Quaternion.identity);
CancelInvoke();
}
}
↧