Enemy objects are spawned in and given movement, first time it’s fine but every other time it creates the objects x2 from the previous amount created
using UnityEngine;
using System.Collections;
public class enemyShips : MonoBehaviour {
public Rigidbody enemyShip;
public Transform spawnPoint1;
public int enemySpeed;
//public Vector3 enemySpawnCoords;
public Transform holdEnemies;
float timer;
bool spawnTime;
// Use this for initialization
void Start () {
spawnTime = false;
}
// Update is called once per frame
void Update () {
timer += Time.deltaTime;
if(timer >= 5){
timer = timer % 5;
spawnTime = true;
print("in timer");
}
if(spawnTime == true){
Rigidbody shipClone;
shipClone = (Rigidbody)Instantiate(enemyShip, spawnPoint1.position, spawnPoint1.rotation);
shipClone.transform.parent = holdEnemies;
print("In spawn");
}
spawnTime = false;
foreach(Transform ship in holdEnemies){
ship.transform.Translate((enemySpeed * Time.deltaTime), 0,0);
if(ship.transform.position.x <= -60){
DestroyObject(ship.gameObject);
}
}
}
}
As your code is placed on every ship your create they will all spawn a new ship. Your update method is called on every ship. Maybe you should place it on some unique object that handle ship creation.