I’ve been teaching myself how to use Unity for the past month or so now. I originally wrote my Enemy Spawner script with hard coded values, and decided to clean and optimize it by using a coroutine and an array. I’ve now hit a snag with the instantiate.
I know WHAT I need to do, but I’m still unfamiliar with Unity.
function SpawnRandomEnemy()
{
//var EnemyPrefab = ChooseRandomPrefab();
var RandomIndex = Random.Range(0, EnemyDroneArrayLength);
Instantiate(EnemyDroneArray[RandomIndex, transform.position, Quaternion.identity]);
//Enemy_Drone_1.Instantiate(Enemy_Drone_1, transform.position, Quaternion.identity);
//Enemy_Drone_2.Instantiate(Enemy_Drone_2, transform.position, Quaternion.identity);
}
I’ve left the commented lines in to show what I’ve been trying. I know that those last 2 lines are not what I want, however they are, in a sense. I know that I want to randomly spawn either enemy 1 or enemy 2 (as I add more basic enemies, this would go up). The last 2 lines will cause both enemies to spawn at the same time, instead of one or the other. With this snippet of code, however, I am receiving this error:
Assets/Main Scene/Scripts/Enemy_Spawn_Script.js(69,32): BCE0017: The best overload for the method 'Array.get_Item(int)' is not compatible with the argument list '(int, UnityEngine.Vector3, UnityEngine.Quaternion)'.
I understand that RandomIndex is an int, I’m just not sure what I am overlooking here. Probably something so simple that the answer is staring me in the face, and I’ll slap myself once I realize what it is.
The entire script can be found here: #pragma strictvar Direction : int = 1;var speed : int = 5;var Enemy_Dr - Pastebin.com. The snippet is located between lines 65 - 73.
Edit: To give a better idea, I have a GameObject “Enemy Spawner” that bounces left and right constantly, and will randomly spawn an enemy at a random interval. The enemies just fall down from the top of the screen to the bottom.