- Home /
Spawning random enemies in spawn points
I have side scrolling game (almost) and I have a little problem with enemy spawnig. I already have spawn points located on map and whenever my BGLooper collides with spawn point it's gonna move forward, next to last spawn point. I can't figure how to spawn 1 of my 8 enemies in each spawnpoint randomly. Any ideas?
using UnityEngine;
using System.Collections;
public class BGLooper : MonoBehaviour {
int numBGPanels = 6;
float minEnemy = 1;
float maxEnemy = 8;
void OnTriggerEnter2D(Collider2D collider) {
Debug.Log ("Triggered: " + collider.name);
float widthOfBGObject = ((BoxCollider2D)collider).size.x;
Vector3 pos = collider.transform.position;
pos.x += widthOfBGObject * numBGPanels;
collider.transform.position = pos;
if (collider.tag == "Enemy") {
}
}
}
Answer by fffMalzbier · May 07, 2014 at 03:29 PM
int enemyType = Mathf.RoundRandom.Range(0,numberOfDifferentEnemys)); Instantiate(EnemyPrefabAray[enemyType],spawnpointPosition ,Quaternion.identity) //not sure about the rotation
Your answer
Follow this Question
Related Questions
Endless/infinite runner random enemy spawning multi lane 1 Answer
How to reduce the chances of a particular enemy spawning ? 3 Answers
Spawning enemies randomly without collisions 3 Answers
Problem with random spawning and coroutine 1 Answer
Spawning different random objects at the same position? 2 Answers