public void AddObject(PoolObjectParams parameters) { int ran = Random.Range(0, objectList.Count); PoolObject enemy = objectList[ran]; GameObject enemyObj = enemy.gameObject; if (!enemyObj.activeInHierarchy) { objectList[ran].gameObject.SetActive(true); enemy.InitializePoolObject(parameters); } }
IEnumerator TimerToSpawn(PoolObjectParams par) { yield return(new WaitForSeconds(3)); AddObject(par); int ran = Random.Range(0, objectPrefab.Length - 1); EnemyMovement enemy = Instantiate(objectPrefab[ran]).GetComponent <EnemyMovement>(); enemy.InitializePoolObject(par); if (player.transform.position.x > 0) { par.startingPosition = new Vector3(-10, -1, 0); } else { par.startingPosition = new Vector3(10, -1, 0); enemy.speed = Mathf.Abs(enemy.speed); } StartCoroutine(TimerToSpawn(par)); }
public abstract void InitializePoolObject(PoolObjectParams parameters);
public override void InitializePoolObject(PoolObjectParams parameters) { transform.position = parameters.startingPosition; }