This is my code:
using UnityEngine;
using System.Collections;
public class Spawn : MonoBehaviour {
public GameObject[] walkers;
public int walkeramount;
public GameObject Walker;
public GameObject[] enemies;
public Rigidbody Enemy;
public int enemyamount;
private Vector3 walkerSpawnPoint;
private Vector3 enemySpawnPoint;
// Update is called once per frame
void Update () {
walkers = GameObject.FindGameObjectsWithTag("Walker");
enemies = GameObject.FindGameObjectsWithTag("Enemy");
walkeramount = walkers.Length;
//keeps track of walkers and stores amount.
if(walkeramount != 20)
{
InvokeRepeating("spawnWalker", 5, 10f);
}
if(enemyamount < 30)
{
InvokeRepeating("spawnEnemy", 3, 3f);
}
}
void spawnWalker()
{
walkerSpawnPoint.x = Random.Range(-20, 20);
walkerSpawnPoint.y = 0.5f;
walkerSpawnPoint.z = Random.Range(-20, 20);
Instantiate(Walker, walkerSpawnPoint, Quaternion.identity);
CancelInvoke();
}
void spawnEnemy()
{
enemySpawnPoint.x = Random.Range(-20, 20);
enemySpawnPoint.y = Random.Range(2, 6);
enemySpawnPoint.z = 5;
Instantiate(Enemy, enemySpawnPoint, Quaternion.identity);
CancelInvoke();
}
}
Despite the fact the code runs without error, when the enemies do spawn, the z axis says 5 yet I have another object called player that has a z position of 5 also yet does not sit anywhere near to it. Is there a reason why two objects would not be using the same scale of position? (I have checked and it is definitely the z axis and not another axis).