- Home /
Need help instantiating enemies between random locations
Trying to take a handful of enemies and spawn random ones in random spots of my side-scroller. below is my code and here is the error I'm reciving:
Assets/Scripts/SpawnEnimies.cs(19,25): error CS1502: The best overloaded method match for UnityEngine.Object.Instantiate(UnityEngine.Object, UnityEngine.Vector3, UnityEngine.Quaternion)' has some invalid arguments Assets/Scripts/SpawnEnimies.cs(19,25): error CS1503: Argument
#1' cannot convert UnityEngine.GameObject[]' expression to type
UnityEngine.Object'
Any suggestions?
using UnityEngine; using System.Collections;
public class SpawnEnimies : MonoBehaviour {
public GameObject[] Enimies; //Assign platform pieces in the inspector
public Vector3 spawnPoint; //Shorter way to grab the position of this platform
void Start () {
print (spawnPoint);
int i = 0;
while (i < 5)
{
spawnPoint = new Vector3(Random.Range(100.0F, 1000.0F), 70, Random.Range(100.0F, 1000.0F));
Instantiate(Enimies, spawnPoint, Quaternion.identity);
i++;
}
}
void Update () {
}
}
Answer by revolute · Aug 22, 2014 at 09:25 AM
You dont put an array as a single GameObject. Make it Enimies[0] or some number other than 0.
Your answer
Follow this Question
Related Questions
How would i use a 2D array for level generation 0 Answers
Random instantiate? 1 Answer
Randomly position Instantiated GameObject's 1 Answer
Spawning objects at random Vector3 3 Answers
spawn muzzle flash with random rotation? 2 Answers