when my object weirdly stays below 200 units on the z axis when spawned outside of it, It just spawns in random places.
public GameObject friendlyUnit;
public int enemyLimit = 3;
public int friendlyLimit = 3;
public float spawnTimerLimit = 5f;
public bool ControlPointable;
public GameObject controlpoint;
public bool Areabound_Allow;
public GameObject areaBound;
AreaBound areabound_Script;
ControlPoint controlpointscript_reference;
private float spawnCount = 5f;
private List<GameObject> spawnedEnemies = new List<GameObject>();
void Start()
{
if (Areabound_Allow == true)
{
areabound_Script = areaBound.GetComponent<AreaBound> ();
}
if (ControlPointable == true)
{
controlpointscript_reference = controlpoint.GetComponent<ControlPoint> ();
}
}
// Use this for initialization
void Update () {
spawnCount -= Time.deltaTime;
foreach(GameObject target in spawnedEnemies)
{
if(target == null)
{
spawnedEnemies.Remove(target);
Destroy(target);
}
}
if(spawnCount <= 0f)
{
spawnCount += spawnTimerLimit;
tryToSpawn();
}
}
// Update is called once per frame
private void tryToSpawn()
{
if(ControlPointable == true)
{
if(controlpointscript_reference.Allegiance == "Green")
return;
}
if (Areabound_Allow == true)
{
if(areabound_Script.friendlies.Count == 0)
return;
}
if (spawnedEnemies.Count < enemyLimit)
{
GameObject newEnemy = (GameObject)Instantiate(enemyUnit);
newEnemy.transform.position = transform.position;
spawnedEnemies.Add(newEnemy);
}
}
}