Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

Spawning with LayerMake

$
0
0
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(); } }

Viewing all articles
Browse latest Browse all 1488

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>