error CS1526: A new expression requires () or [] after type
I want to do spawnvalues . I can spawn enemy ai by z, x, . I only got one error :
Here is my script :
using UnityEngine;
using System.Collections;
public class EnemiesSpawner : MonoBehaviour {
public GameObject[] enemy;
public Transform [] spawnPoints;
public float spawnTime = 5f;
public Vector3 spawnValues;
void Start () {
InvokeRepeating("Spawn", spawnTime, spawnTime); //Calls the "Spawn" function every 10 seconds.
}
void Spawn () {
int spawnPointIndex = Random.Range (0, spawnPoints.Length -1); for( int spawnCount = 2 - 1 ; spawnCount >= 0 ; --spawnCount )
Instantiate(enemy, spawnPoints[spawnPointIndex].position, spawnPoints[spawnPointIndex].rotation);
Vector3 spawnPosition = new Vector3 (Random.Range (-spawnValues.x, spawnValues.x), 1, Random.Range (-spawnValues.z, -spawnValues.z);
}
}
Answer by saschandroid · Aug 17, 2016 at 09:45 AM
Missing ")" at the end of line 18/19?
Vector3 spawnPosition = new Vector3 (Random.Range (-spawnValues.x, spawnValues.x), 1, Random.Range (-spawnValues.z, -spawnValues.z);
Vector3 spawnPosition = new Vector3 (Random.Range (-spawnValues.x, spawnValues.x), 1, Random.Range (-spawnValues.z, -spawnValues.z) ) ; // <= here
I got two errors :
.cs(18,20): error CS1502: The best overloaded method match for UnityEngine.Object.Instantiate(UnityEngine.Object, UnityEngine.Vector3, UnityEngine.Quaternion)' has some invalid arguments .cs(18,20): error CS1503: Argument
#1' cannot convert UnityEngine.GameObject[]' expression to type
UnityEngine.Object'
enemy
is an array of gameobjects here. If you want to spawn one gameobject from the array you have to use something like:
Instantiate(enemy[0], ...
I don't have error when I added the Instantiate(enemy[0]
I have another line of for spawning is that gonna mess up anything? It's start at int spawncount : Here is my code now :
using UnityEngine;
using System.Collections;
public class EnemiesSpawner : $$anonymous$$onoBehaviour {
public GameObject[] enemy;
public Transform [] spawnPoints;
public float spawnTime = 5f;
public Vector3 spawnValues;
void Start () {
InvokeRepeating("Spawn", spawnTime, spawnTime); //Calls the "Spawn" function every 10 seconds.
}
void Spawn () {
int spawnPointIndex = Random.Range (0, spawnPoints.Length -1); for( int spawnCount = 2 - 1 ; spawnCount >= 0 ; --spawnCount )
Instantiate(enemy[10], spawnPoints[spawnPointIndex].position, spawnPoints[spawnPointIndex].rotation);
Vector3 spawnPosition = new Vector3 (Random.Range (-spawnValues.x, spawnValues.x), 1, Random.Range (-spawnValues.z, -spawnValues.z) ) ; // <= here
}
}